Please, help! What I'm doing wrong? I'm new to Angular, but it behaives in very strange manner.
Controller:
function cItemsList($scope, ItemsList) {
ItemsList.getList(function (res) {
$scope.items = res;
});
};
Items service:
var appServices = angular.module('appServices', []);
appServices.factory('ItemsList', ['AppSettigns', function($settings) {
return {
getList: function (callbackSuccess, callbaclError) {
// emulate http request...
setTimeout(function(){
callbackSuccess([{title: 'bla bla bla'}]);
}, 1000);
}
};
}]);
Partial ('/js/app/views/index.html'):
<div class="column">
<div class="column-body">
<ul ng-controller="cItemsList">
<li ng-repeat="itm in items">
{{itm.title}}
</li>
</ul>
</div>
</div>
Router:
var APP = angular.module('APP', ['appServices']);
APP.config(
function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true).hashPrefix('!');
$routeProvider.
when('/', {
templateUrl: '/js/app/views/index.html'
}).
otherwise({redirectTo: '/'});
}
);
And when I change this:
when('/', {
templateUrl: '/js/app/views/index.html'
}).
to this:
when('/', {
templateUrl: '/js/app/views/index.html',
controller: cItemsList
}).
, controller initializes twice. Is it my fault or bug in Angular?