-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using Controller As Syntax #223
Comments
I'm not really catching up with all the latest goodies from Angular lately. |
Use 'vm.countries' for instance as the 'local-data' attribute. Then as the 'selected object' you can use vm.selectedCountry (name it whatever you like) which you can then access from your controller |
Facing the same issue while using ES6 classes. "this" refers to the current scope inside the update function while it should refers to our class. <angucomplete-alt placeholder="Départ..." pause="250" local-data="vm.places" search-fields="name" title-field="name" text-searching="Récupération en cours..." no-result="Aucun résultat trouvé"
input-changed="vm.updateInput"></angucomplete-alt> class Foo {
constructor(api) {
this.api = api;
this.places = [];
}
updateInput(string) {
console.log(this); // Refers to the controller scope, not the class itself
}
} |
I tried using a closure, but angular gave an infinite digest error. I changed the code above to this: <angucomplete-alt placeholder="Départ..." pause="250" local-data="vm.places" search-fields="name" title-field="name" text-searching="Récupération en cours..." no-result="Aucun résultat trouvé"
input-changed="vm.updateInput().update"></angucomplete-alt> class Foo {
constructor(api) {
this.api = api;
this.places = [];
}
updateInput(string) {
var self = this;
return {
update: function(string){
console.log(self); // Refers to class now, but angular gave an infinite digest error
}
}
}
} Here's a plunker: |
Any progress on this or workaround suggestions. This is only when you inline the controller in html ng-controller="SomeController as vm" the digest errors occur. The same controller from a route with controllerAs works but SomeController as vm gives the same digest errors as inline. Any help? |
@wendellm Can you create a plnkr example? |
So finally, I think I got figured this out. Using @thiphariel's example <angucomplete-alt placeholder="Départ..." pause="250" local-data="vm.places" search-fields="name" title-field="name" text-searching="Récupération en cours..." no-result="Aucun résultat trouvé"
input-changed="vm.updateInput().update"></angucomplete-alt> class Foo {
constructor(api) {
this.api = api;
this.places = [];
var self = this;
this.updateInput = function(string) {
console.log(self); // Refers to the class now
}
}
} Updated plunkr: https://plnkr.co/edit/wjWPkoKtILEeRVHjtBJY?p=preview |
I am using controller as Syntax and am facing issues while trying to access 'this' variable for the controller inside remote-api-handler function.
The text was updated successfully, but these errors were encountered: