您的位置:首页 > Web前端 > AngularJS

AngularJs 使用 .value / .constant

2016-04-06 16:23 399 查看
app.js文件
angular.module('myApp', [
'ngRoute',
'myApp.view1',
'myApp.view2',
'myApp.version'
])

.value('version', '5000')
.value('testValue1', '10000')
.constant('testValue2', '20000')

.config(['$routeProvider', function($routeProvider) {
$routeProvider.otherwise({redirectTo: '/view1'});
}]);

view1.js
'use strict';

angular.module('myApp.view1', ['ngRoute'])

.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/view1', {
templateUrl: 'view1/view1.html',
controller: 'View1Ctrl'
});
}])

.controller('View1Ctrl', ['$scope', 'version', 'testValue1', 'testValue2', function($scope, version, testValue1, testValue2) {
console.log('version=' + version);
console.log('testValue1=' + testValue1);
console.log('testValue2=' + testValue2);
}]);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: