app.js中的写法:
var app=angular.module('birthdayApp',['ngRoute']); app.config(function($routeProvider){ $routeProvider .when('/', { templateUrl: 'views/login.html', controller: 'loginCtr', controllerAs: 'login' }) .when('/regist', { templateUrl: 'views/regist.html', controller: 'registCtr', controllerAs: 'regist' }) .otherwise({ redirectTo: '/' }); });
<script src='./angular-1.4.0-rc.2/angular-route.js'></script>html中的写法:
<div ng-view></div>
var app=angular.module('birthdayApp',['ui.router']); app.config(function($stateProvider,$urlRouterProvider){ $urlRouterProvider.otherwise('/login'); $stateProvider .state('login', { url: "/login", views: { 'view': { templateUrl: 'views/login.html', controller: 'loginCtr' } } }); $stateProvider .state('regist', { url: "/regist", views: { 'view': { templateUrl: 'views/regist.html', controller: 'registCtr' } } }); });
<script src='./angular-1.4.0-rc.2/angular-ui-router.js'></script>
<div ui-view="view"></div>