angularJs模版注入的两种方式
一,声名式注入
1:app.js:
var myApp = angular.module("myApp",["ngRoute"]);
2:controller.js:
myApp.controller("indexCtrl",['$scope',function($scope){ //如果想用混淆,必须使用中括号中声名注入参数
}])
3:config.js:
myApp.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/a', {
templateUrl: 'web/templates/a.html',
controller: 'aController'
})
.when('/b', {
templateUrl: 'web/templates/b.html',
controller: 'bController',
.otherwise({
redirectTo: '/a'
});
});
二,直接注入
1:app.js
angular.moudle("myApp",[
'ngRoute',
'myApp.config',
'myApp.controllers'
]);
2:controllers.js
angular.module("myApp.controllers",[]) //如果想用混淆,必须使用中括号中声名注入参数
.controller("myCtrl",function($scope){
})
.controller("otherCtrl",function($scope){
})
3:config.js
angular.module("myApp.config",[])
.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/a', {
templateUrl: 'web/templates/a.html',
controller: 'aController'
})
.when('/b', {
templateUrl: 'web/templates/b.html',
controller: 'bController',
.otherwise({
redirectTo: '/a'
});
});