I'm attempting to pre-populate a select list with data from a JSON file.
Controller
this.langs = [];
var promise = $lcidFactory.getLCIDS();
promise.then(
function(payload){
this.langs = payload.data;
console.log(payload.data);
},
function(error){
alert("[Error] "+error);
}
);
When I review the console with the inspector the data appears. However, the following code produces an empty JSON, {}
.
HTML
<template-editor-form model="cpCtrl.data">
...
<pre>{{ cpCtrl.langs | json }}</pre>
...
</template-editor-form>
If I set this.langs = []
in line 1 of the controller to this.langs = ["one"]
the template reflects the changes properly, as ["langs": ["one"]]
EDIT
This question is similar to How does the "this" keyword work?, however this question addresses one of the common pitfalls of the usage of this
in the context of AngularJS, in a concise fashion.