preboot / angularjs-webpack

A complete, yet simple, starter for AngularJS using webpack
MIT License
1.71k stars 658 forks source link

ui-router $state #71

Closed fecabianchi closed 7 years ago

fecabianchi commented 7 years ago

Hi, how can i inject $state on the controller?

Thanks in advance.

phra commented 7 years ago

w/ ES6 you have to inject deps as arguments of the constructor of the ES6 class. if you use preprocessing tools like ng-inject you have to add the string literals "ngInject"; as first line of the constructor.

class AppCtrl {
  constructor($myDependency) {
    'ngInject';
    this.url = 'https://github.com/preboot/angular-webpack'
    this.myDependency = $myDependency
  }
}

feel free to reopen if you have have problems.

fecabianchi commented 7 years ago

Thanks for the answer but i still have problems...

i'm trying to do like that

export default class LoginController {
  constructor($state) {
    'ngInject';
    this.state = $state
  }
  changeState() {
    state.go('app.home')
  }
}

but when i fire changeState nothing happens.

phra commented 7 years ago

you have missed the this keyword in changeState function. (it's a ES6 class)