angularjs - Angular ngRoute cannot get view -
angularjs - Angular ngRoute cannot get view -
i trying utilize angular's routing mechanism in app, on clicking on element should cause routing i'm getting cannot viewname, viewname view.
this app.js script file:
var app = angular.module('actsapp', ['ngroute']); //define routing app app.config(['$routeprovider', function($routeprovider) { $routeprovider .when('/', { templateurl: 'views/student_list.html', controller: 'studentlistcontroller' }) .when('/students', { templateurl: 'views/student_list.html', controller: 'studentlistcontroller' }) .when('/registerstudent', { templateurl: 'views/register_student.html', controller: 'studentregistrationcontroller' }); }]); app.controller('studentlistcontroller', function($scope) { $scope.message = 'this pupil list screen'; }); app.controller('studentregistrationcontroller', function($scope) { $scope.message = 'this pupil registration screen'; });
and index.html:
<!doctype html> <html ng-app="actsapp"> <head> <title></title> <link href="style/style.css" rel="stylesheet" /> <link href="style/bootstrap.css" rel="stylesheet" /> <script src="scripts/jquery-1.js"></script> <script src="scripts/angular/angular.js"></script> <script src="scripts/angular/angular-route.js"></script> <script src="scripts/angular/app.js"></script> </head> <body> <div class="header"> <div class="heading_wrap"> <h1>student registration form</h1> </div> </div> <div class="nav-wrap"> <ul class="nav nav-acts-pills nav-stacked "> <li class="active"> <a href="/students">student list</a> </li> <li> <a href="/registerstudent">add student</a> </li> <li> <a>add students (by school)</a> </li> </ul> </div> <div ng-view="" class="content-wrap" style="float:left;"> </div> </body> </html>
any suggestions on how prepare much more welcome. based work on latest version of ngroute documentation. give thanks you.
you need add together #
below work routing:
<li class="active"> <a href="#/students">student list</a> // add together # </li> <li> <a href="#/registerstudent">add student</a> // add together # </li>
and in .js file, templateurl
should like: /views/student_list.html
.
however, if need routes without #
, need add together $locationprovider.html5mode(true);
. check illustration here larn how avoid using #
. also, see this. demo says that:
app.config(['$routeprovider', function($routeprovider,$locationprovider) { $routeprovider .when('/', { templateurl: '/views/student_list.html', // urls should controller: 'studentlistcontroller' }) .when('/students', { templateurl: '/views/student_list.html', // urls should controller: 'studentlistcontroller' }) .when('/registerstudent', { templateurl: '/views/register_student.html', // urls should controller: 'studentregistrationcontroller' }); $locationprovider.html5mode(true); }]); ]
in view :
<li class="active"> <a href="/students">student list</a> </li> <li> <a href="/registerstudent">add student</a> </li>
angularjs ngroute angularjs-ng-route
Comments
Post a Comment