angularJs设置全局变量

var app= angular.module('myApp', []);  
 
//方法1 value 
app.value("public",{
  "Localapi":"/v1/getInfo/",
  "Versions":"V2.2.3"
}); 

//方法2 constant  
app.constant("option", function(){
   
	return {
		local : function(str) {
		  return "text"
		},
		Localapi : "/v1/getInfo/",
		array : [200,300,500,600]
	}

}); 
  
//使用,注入public
app.controller("Demo",["$scope","public",function($scope,public){

	 $scope.public = public;
 
}]);

//使用,注入public
app.controller("Demo2",["$scope","option",function($scope,option){
	 $scope.option = option();
}]);

 

你可能感兴趣的:(Angularjs)