<title></title>
<script type="text/javascript" src="../../angular/angular.js" ></script>
<script>
var app = angular.module("myApp",[]);
//配置函数:做程序的初始化配置。
app.config(function(myProviderProvider){
myProviderProvider.setAge(20);
//myServiceProvider.hehe(30);
});
app.controller("myCtrl",function($scope,myProvider,myService){
$scope.food = myProvider.food;
$scope.age = myProvider.resultAge;
//思路一:
myService.hehe(30);
$scope.num = myService.num1;
//思路二:
//$scope.num = myService.hehe(30);
});
//自定义provider服务
app.provider("myProvider",function(){
var age;
this.setAge = function(newAge){
age = newAge;
}
this.$get = function(){
var result = {};
result.food = "唐僧肉";
result.resultAge = age;
return result;
};
});
app.service("myService",function(){
//思路一:
this.num1;
this.hehe = function(num){
this.num1 = num;
}
//思路二:
/*var num1;
this.hehe = function(num){
num1 = num;
return num1;
}*/
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<p>食物:{{food}},吃了{{age}}年了</p>
<p>num的值为:{{num}}</p>
</body>
<script type="text/javascript" src="../../angular/angular.js" ></script>
<script>
var app = angular.module("myApp",[]);
//配置函数:做程序的初始化配置。
app.config(function(myProviderProvider){
myProviderProvider.setAge(20);
//myServiceProvider.hehe(30);
});
app.controller("myCtrl",function($scope,myProvider,myService){
$scope.food = myProvider.food;
$scope.age = myProvider.resultAge;
//思路一:
myService.hehe(30);
$scope.num = myService.num1;
//思路二:
//$scope.num = myService.hehe(30);
});
//自定义provider服务
app.provider("myProvider",function(){
var age;
this.setAge = function(newAge){
age = newAge;
}
this.$get = function(){
var result = {};
result.food = "唐僧肉";
result.resultAge = age;
return result;
};
});
app.service("myService",function(){
//思路一:
this.num1;
this.hehe = function(num){
this.num1 = num;
}
//思路二:
/*var num1;
this.hehe = function(num){
num1 = num;
return num1;
}*/
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<p>食物:{{food}},吃了{{age}}年了</p>
<p>num的值为:{{num}}</p>
</body>