leftstick / generator-es6-angular

Yeoman generator for es6 based angular skeleton
https://leftstick.github.io/generator-es6-angular
MIT License
74 stars 18 forks source link

On generator-es6-angular How to inject function in the controller problem #13

Closed homx closed 7 years ago

homx commented 7 years ago

Hello, I now use the framework, now encountered some problems, I would like to inject a function in the controller, such as: $ timeout or hotkeys, but can not be achieved, please indicate, thank you!

leftstick commented 7 years ago

Can you put it specifically? I am not sure i got your points.

An example would be better

homx commented 7 years ago

`class SearchController {

/*@ngInject*/
constructor($scope) {
    this.$scope = $scope;
    this._init_();
    this._destroy_();
}

_init_() {

}

_destroy_() {
    this.$scope.$on('$destroy', function() {});
}

}

export default SearchController;`

The above is my controller, I need a $ timeout controller, ask how injection

leftstick commented 7 years ago

It's easy to achieve, just like shown at HomeController.js#L12

Specify it in the constructor, as following:

/*@ngInject*/
constructor($scope, $timeout) {
    this.$scope = $scope;
    this.$timeout = $timeout;

    this._init_();
    this._destroy_();
}

This feature is provided by ng-annotate, if you see more read