Я пытаюсь назначить переменную из $ http.get(), хотя conf var имеет значение null, несмотря на то, что запрос проходит и возвращает json.
app.factory('Config', ['$http',
function($http) {
return {
conf: null,
init: function () {
if (this.conf === null) {
$http.get('/config')
.success(function (data) {
this.conf = data;
});
}
}
}
}
]);
this
внутренняя success callback function
отличается
app.factory('Config', ['$http',
function($http) {
return {
conf: null,
init: function () {
var self = this;
if (this.conf === null) {
$http.get('/config')
.success(function (data) {
self.conf = data;
});
}
}
}
}
]);