function ExampleCtrl(HttpGet){
'ngInject';
const vm = this;
vm.title = 'test';
HttpGet.get().then(function(response){
console.log(vm.title); //logs 'test';
vm.response = response.data;
console.log(vm.response); //logs the response;
});
}
export default {
name : 'ExampleCrl',
fn : ExampleCtrl
};
My View:
{{ home.response }}
UI Router:
$stateProvider
.state('Home', {
url : '/home/:page',
controller : 'ExampleCtrl as home',
templateUrl: 'home.html',
title : 'Home'
});
HttpGet
Service:
function HttpGet($http) {
'ngInject';
const service = {};
service.get = function () {
return new Promise(function(resolve, reject) {
$http.get('http://localhost:8000/all').success((data) => {
resolve(data);
}).error((err, status) => {
reject(err, status);
});
});
};
return service;
}
export default {
name: 'HttpGet',
fn: HttpGet
};
Isn't the whole point of doing vm=this
is that inside a function block this
is still bound ?