5
5
< meta charset ="UTF-8 ">
6
6
< title > </ title >
7
7
</ head >
8
+ < script type ="text/javascript " src ="../js/angular.js "> </ script >
8
9
9
10
< body ng-app ="angularRouteDemo ">
10
11
< section ng-controller ="homeCtrl ">
11
12
< p > {{test}}</ p >
13
+ < p > {{name}}</ p >
14
+ < input ng-model ="name " />
15
+ < button ng-click ="submit() "> 提交</ button >
12
16
</ section >
17
+ <!--<section ng-controller="addCtrl">
18
+
19
+ </section>-->
13
20
</ body >
14
21
< script >
15
22
var app = angular . module ( 'angularRouteDemo' , [ ] ) ;
16
- app . controller ( 'homeCtrl' , [ '$scope' , '$http' , function ( $scope , $http ) {
17
- $scope . test = "123" ;
18
- } ] )
23
+ app . controller ( 'homeCtrl' , [ '$scope' , '$http' , '$interval' , 'intance' , function ( $scope , $http , $interval , intance ) {
24
+ $scope . test = "123" ;
25
+ $scope . name = '1' ;
26
+ console . log ( intance ) ;
27
+ // window.setInterval(function(){
28
+ // $scope.name = 2;
29
+ // },1000);
30
+ // $interval(function() {
31
+ // console.log("1");
32
+ // }, 1000)
33
+ console . log ( intance . name )
34
+ console . log ( intance . addFunc ( 1 , 2 ) ) ;
35
+
36
+ $scope . submit = function ( ) {
37
+ $http . get ( 'http://1.wsscatapi.applinzi.com/?format=' + $scope . name ) . success ( function ( e ) {
38
+ console . log ( e ) ;
39
+ $scope . name = e ;
40
+ } )
41
+ }
42
+ } ] )
43
+ // app.controller('addCtrl',['$scope', '$http', 'intance', function($scope, $http, intance){
44
+ // console.log(intance);
45
+ // }])
46
+ // app.factory('intance',function(){
47
+ // return {};
48
+ // })
49
+ app . service ( 'intance' , [ function ( ) {
50
+ var obj = { } ;
51
+ obj . addFunc = function ( a , b ) {
52
+ return a + b ;
53
+ }
54
+ //obj.name = 'yao';
55
+ obj [ 'name' ] = 'yao' ;
56
+ return obj ;
57
+ //console.log("这是我的服务");
58
+ } ] )
19
59
</ script >
20
60
21
61
</ html >
0 commit comments