AngularJs 使用 .value / .constant

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);
}]);

你可能感兴趣的:(html)