在angular中如何创建一个路由
方法1
- template.html
<div ng-controller="homeController">
{{name}}
</div>
- app.js
var Webmall = angular.module('Webmall', []);
Webmall.config(['$routeProvider', function ($routeProvider) {
$routeProvider.otherwise({redirectTo: '/home'});
$routeProvider.when('/home', {
templateUrl: 'views/home/template.html',
//controller: HomeController
});
}]);
- homeController.js
Webmall.controller('homeController', function ($scope) {
$scope.name = 'kkkkk';
});
方法2
- template.html
<div>
{{name}}
</div>
- app.js
var Webmall = angular.module('Webmall', []);
Webmall.config(['$routeProvider', function ($routeProvider) {
$routeProvider.otherwise({redirectTo: '/home'});
$routeProvider.when('/home', {
templateUrl: 'views/home/template.html',
controller: HomeController
});
}]);
- homeController.js
var HomeController = function ($scope) {
$scope.name = 'kkkkk';
};