im fairly new to angular. im trying to understand why this doesnt work:
error recieved is:
Uncaught Error: [$injector:modulerr] Failed to instantiate module phonecatApp due to: Error: [$injector:modulerr] Failed to instantiate module phoneList due to: TypeError: Cannot read property 'controller' of undefined
angular.
module('phoneList').
component(name, component);
var name = 'phoneList';
var component = {
templateUrl: 'phone-list/phone-list.template.html',
controller: ['$http', function PhoneListController($http) {
var self = this;
self.orderProp = 'age';
$http.get('phones/phones.json').then(function(response) {
self.phones = response.data;
});
}]
};
how can i fix this ?
i know i can do this but i prefer decomposing the object as above. please advise
angular.
module('phoneList').
component('phoneList', {
templateUrl: 'phone-list/phone-list.template.html',
controller: ['$http', function PhoneListController($http) {
var self = this;
self.orderProp = 'age';
$http.get('phones/phones.json').then(function(response) {
self.phones = response.data;
});
}]
});