File tree 7 files changed +104
-2
lines changed 7 files changed +104
-2
lines changed Original file line number Diff line number Diff line change 6
6
var app = angular . module ( 'app' , [ ] ) ;
7
7
app . service ( 'userService' , function ( $http ) {
8
8
this . getUser = function ( ) {
9
- return $http . get ( 'users.json' ) ;
9
+ return $http . get ( '/mock/ users.json' ) ;
10
10
} ;
11
11
} ) ;
12
12
app . controller ( 'MyController' , function ( userService ) {
Original file line number Diff line number Diff line change 14
14
deferred . resolve ( _privateUser ) ;
15
15
return deferred . promise ;
16
16
}
17
- return $http . get ( 'users.json' ) . then ( function ( res ) {
17
+ return $http . get ( '/mock/ users.json' ) . then ( function ( res ) {
18
18
_privateUser = res . data ;
19
19
return _privateUser ;
20
20
} ) ;
Original file line number Diff line number Diff line change
1
+ < html >
2
+
3
+ < head >
4
+ < script type ="text/javascript " src ="../../bower_components/angular/angular.js "> </ script >
5
+ < script type ="text/javascript ">
6
+ var app = angular . module ( 'app' , [ ] ) ;
7
+
8
+ app . service ( 'userService' , function ( $http ) {
9
+ this . getUser = function ( ) {
10
+ return $http . get ( '/mock/users.json' ) ;
11
+ } ;
12
+ this . getUserError = function ( ) {
13
+ return $http . get ( 'usersss.json' )
14
+ } ;
15
+ } ) ;
16
+
17
+ app . controller ( 'MyController' , function ( userService ) {
18
+ var self = this ;
19
+
20
+ this . getUserError = function ( ) {
21
+ userService
22
+ . getUserError ( )
23
+ . then ( function ( res ) {
24
+ self . users = res ;
25
+ } , function ( err ) {
26
+ self . users = err ;
27
+ console . log ( 'Bad Request!!!' ) ;
28
+ } ) ;
29
+ } ;
30
+
31
+ this . getUser = function ( ) {
32
+ userService
33
+ . getUser ( )
34
+ . then ( function ( res ) {
35
+ self . users = res ;
36
+ } ) ;
37
+ }
38
+ } ) ;
39
+
40
+ </ script >
41
+ </ head >
42
+
43
+ < body ng-app ="app " ng-controller ="MyController as my ">
44
+
45
+ < h4 > $http usage</ h4 >
46
+ < button type ="button " ng-click ="my.getUser() "> SUCCESS</ button > < button type ="button " ng-click ="my.getUserError() "> ERROR</ button >
47
+ < pre > {{ my.users | json }}</ pre >
48
+
49
+ </ body >
50
+
51
+ </ html >
Original file line number Diff line number Diff line change
1
+ < html >
2
+
3
+ < head >
4
+ < script type ="text/javascript " src ="../../bower_components/angular/angular.js "> </ script >
5
+ < script type ="text/javascript ">
6
+ var app = angular . module ( 'app' , [ ] ) ;
7
+
8
+ app . service ( 'userService' , function ( $http ) {
9
+ this . getUser = function ( ) {
10
+ return $http . get ( '/mock/users.json' ) ;
11
+ } ;
12
+ this . getUserError = function ( ) {
13
+ return $http . get ( 'usersss.json' )
14
+ } ;
15
+ } ) ;
16
+
17
+ app . controller ( 'MyController' , function ( userService ) {
18
+ var self = this ;
19
+
20
+ this . getUserError = function ( ) {
21
+ userService
22
+ . getUserError ( )
23
+ . then ( function ( res ) {
24
+ self . users = res ;
25
+ } , function ( err ) {
26
+ self . users = err ;
27
+ console . log ( 'Bad Request!!!' ) ;
28
+ } ) ;
29
+ } ;
30
+
31
+ this . getUser = function ( ) {
32
+ userService
33
+ . getUser ( )
34
+ . then ( function ( res ) {
35
+ self . users = res ;
36
+ } ) ;
37
+ }
38
+ } ) ;
39
+
40
+ </ script >
41
+ </ head >
42
+
43
+ < body ng-app ="app " ng-controller ="MyController as my ">
44
+
45
+ < h4 > $http usage</ h4 >
46
+ < button type ="button " ng-click ="my.getUser() "> SUCCESS</ button > < button type ="button " ng-click ="my.getUserError() "> ERROR</ button >
47
+ < pre > {{ my.users | json }}</ pre >
48
+
49
+ </ body >
50
+
51
+ </ html >
File renamed without changes.
You can’t perform that action at this time.
0 commit comments