angularjs - angular Routing: when I call controller the second will be executed -
im uning angular make page login, use template login.html , controller login.html, problem when call login controller main controller executed automatically !
and found : warning: tried load angular more once.
this js:
trainingapp.config(['$routeprovider' ,function($routeprovider){ $routeprovider .when('/login',{ templateurl: 'login.html', controller: 'loginctrl' }) .when('/',{ templateurl: 'index.html', controller: 'mainctrl' }) .otherwise({ redirectto : "/" }); }]); trainingapp.controller('loginctrl',['$scope', function($scope){ $scope.alertt = function(){ // console.log("ok"); alert("okkkkkkk"); } }]); trainingapp.controller('mainctrl', ['$scope','$timeout', 'apiservice','$location', function ($scope,$timeout, apiservice,$location) { console.log('hello'); }]);
index.html
<!doctype html> <html lang="fr"> <head> <meta charset="utf-8"> <title>plannification des formations</title> <link rel="stylesheet" type="text/css" href="mystyle/bootstrap-tokenfield.css"> <link rel="stylesheet" type="text/css" href="mystyle/bootstrap.min.css"> <link rel="stylesheet" href="mystyle/bootstrap-datepicker.css"> <link rel="stylesheet" href="mystyle/jquery-ui.css"> <script src="public/jquery-1.11.2.min.js"></script> <script src="public/jquery-ui.js"></script> <script src="public/bootstrap-datepicker.js"></script> <script src="node_modules/lodash/lodash.js"></script> <script src="bower_components/angular/angular.min.js"></script> <script src="bower_components/angular-route/angular-route.min.js"></script> <script src="bower_components/moment/min/moment-with-locales.min.js"></script> <script src="public/daypilot/daypilot-all.min.js"></script> <script src="public/bootstrap-tokenfield.js"></script> <script src="public/bootstrap.min.js"></script> <!-- <script src="bower_components/angular-route/angular-route.js"></script> --> <script src="controllers/app.js"></script> <script src="controllers/maincrtl.js"></script> <script src="services/apiservice.js"></script> </head> <body data-ng-app="training" data-ng-controller="mainctrl" ng-view> ....... </body> </html>
login.html
<button id="btn-login" class="btn btn-success " ng-href="#!/">login </button>
please remove ng-controller="mainctrl"
html
, have defined controller in $routeprovider
config.
Comments
Post a Comment