I'm Angularjs novice and Restangular noob.
Here is my problem :
On my main controller I have this:
angular.module('examplesiteApp')
.controller('MainCtrl', function ($scope,$location,Restangular) {
Restangular.setBaseUrl('http://api.example.com/api/v1/');
var baseAccounts = Restangular.all('auth/register/');
console.log(baseAccounts);
at this command I get two elements (the same) logged in my console.
I have read a similar question and it says that using ng-controller
with $routeProvider
that causes the problem.
Here is my app.js
.config(function ($routeProvider, $locationProvider,uiGmapGoogleMapApiProvider) {
uiGmapGoogleMapApiProvider.configure({
key: 'secret_shit_or_not',
v: '3.17',
libraries: 'geometry,visualization,places'
});
$routeProvider
.when('/', {
templateUrl: 'views/home/slider.html',
controller: 'MainCtrl'
})
The template looks like :
<body ng-controller="GeneralCtrl">
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<!-- Add your site or application content here -->
<div ng-include src="'views/main.html'"></div>
<div ng-view></div>
depending on the url ng-view gets a defined value (dynamic process). The GeneralController is a simple controller:
angular.module('peersiteApp')
.controller('GeneralCtrl', function ($scope , $location) {
$scope.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'Karma'
];
$scope.isAt = function(route){
return route === $location.path();
};
});
Can you tell me why I'm having Restangular firing twice ? Help the Angular John snow which I am.
Found the solution :
I was calling ng-controller inside a sub view.