javascript - Routing problems with AngularJS -
i don't understand why routing doesn't work, "otherwise" case working, when click in 1 of menu routing doesn't automatically load relative page. can me understand what's wrong code please?
this code relative routing part:
var mycolors = angular.module('myfirstmodule', ['ngroute']); mycolors.config(['$routeprovider', function($routeprovider) { $routeprovider .when('/home', { templateurl: 'home.html' }) .when('/directory', { templateurl: 'directory.html', controller: 'myfirstmodule' }).otherwise({ redirectto: '/directory' }); }]); here html div put links:
<ul> <li><a href="#/home">home </a></li> <li><a href="#/directory">directory</a></li> </ul> here plunker of full code
you using wrong controller name , @mistalis told have include #! in href. if want remove ! use $locationprovider.hashprefix(''); in config. can use href without !
js
var mycolors = angular.module('myfirstmodule', ['ngroute']); mycolors.config(['$routeprovider', function($routeprovider) { $routeprovider .when('/home', { templateurl: 'home.html' }) .when('/directory', { templateurl: 'directory.html', controller: 'myfirstcontroller' //use controller name here }).otherwise({ redirectto: '/directory' }); }]); html
<ul> <li><a href="#!/home">home </a></li> <li><a href="#!/directory">directory</a></li> </ul> working plunker: https://plnkr.co/edit/gaob2u4mdnzxxlttzmg2?p=preview
Comments
Post a Comment