Commit 652ee29 1 parent 07bf004 commit 652ee29 Copy full SHA for 652ee29
File tree 9 files changed +144
-0
lines changed
9 files changed +144
-0
lines changed Original file line number Diff line number Diff line change
1
+ [
2
+ {
3
+ "id" : 1 ,
4
+ "name" : " Peyton Manning" ,
5
+ "phone" : " (303) 567-8910" ,
6
+ "address" : {
7
+ "street" : " 1234 Main Street" ,
8
+ "city" : " Greenwood Village" ,
9
+ "state" : " CO" ,
10
+ "zip" : " 80111"
11
+ }
12
+ },
13
+ {
14
+ "id" : 2 ,
15
+ "name" : " Demaryius Thomas" ,
16
+ "phone" : " (720) 213-9876" ,
17
+ "address" : {
18
+ "street" : " 5555 Marion Street" ,
19
+ "city" : " Denver" ,
20
+ "state" : " CO" ,
21
+ "zip" : " 80202"
22
+ }
23
+ },
24
+ {
25
+ "id" : 3 ,
26
+ "name" : " Von Miller" ,
27
+ "phone" : " (917) 323-2333" ,
28
+ "address" : {
29
+ "street" : " 14 Mountain Way" ,
30
+ "city" : " Vail" ,
31
+ "state" : " CO" ,
32
+ "zip" : " 81657"
33
+ }
34
+ }
35
+ ]
Original file line number Diff line number Diff line change 3
3
// Declare app level module which depends on views, and components
4
4
angular . module ( 'myApp' , [
5
5
'ui.router' ,
6
+ 'ngResource' ,
6
7
'myApp.view1' ,
7
8
'myApp.view2' ,
8
9
'myApp.version'
Original file line number Diff line number Diff line change 5
5
body {
6
6
padding : 10px ;
7
7
}
8
+
9
+ table {
10
+ margin-top : 10px ;
11
+ border-collapse : collapse;
12
+ width : 100% ;
13
+ }
14
+
15
+ th {
16
+ text-align : left;
17
+ border-bottom : 2px solid # ddd ;
18
+ padding : 8px ;
19
+ }
20
+
21
+ td {
22
+ border-top : 1px solid # ddd ;
23
+ padding : 8px ;
24
+ }
25
+
Original file line number Diff line number Diff line change 18
18
< ul class ="menu ">
19
19
< li > < a ui-sref ="view1 "> view1</ a > </ li >
20
20
< li > < a ui-sref ="view2 "> view2</ a > </ li >
21
+ < li > < a ui-sref ="search "> search</ a > </ li >
21
22
</ ul >
22
23
23
24
<!--[if lt IE 7]>
31
32
<!-- build:js js/seed.min.js -->
32
33
< script src ="bower_components/angular/angular.js "> </ script >
33
34
< script src ="bower_components/angular-ui-router/release/angular-ui-router.js "> </ script >
35
+ < script src ="bower_components/angular-resource/angular-resource.js "> </ script >
34
36
< script src ="app.js "> </ script >
35
37
< script src ="view1/view1.js "> </ script >
36
38
< script src ="view2/view2.js "> </ script >
39
+ < script src ="search/search.state.js "> </ script >
40
+ < script src ="search/search.controller.js "> </ script >
41
+ < script src ="search/search.service.js "> </ script >
37
42
< script src ="components/version/version.js "> </ script >
38
43
< script src ="components/version/version-directive.js "> </ script >
39
44
< script src ="components/version/interpolate-filter.js "> </ script >
Original file line number Diff line number Diff line change
1
+ ( function ( ) {
2
+ 'use strict' ;
3
+
4
+ angular
5
+ . module ( 'myApp' )
6
+ . controller ( 'SearchController' , SearchController ) ;
7
+
8
+ SearchController . $inject = [ 'SearchService' ] ;
9
+
10
+ function SearchController ( SearchService ) {
11
+ var vm = this ;
12
+
13
+ vm . search = function ( ) {
14
+ SearchService . search ( vm . term , function ( response ) {
15
+ vm . searchResults = response ;
16
+ } ) ;
17
+ } ;
18
+ }
19
+ } ) ( ) ;
Original file line number Diff line number Diff line change
1
+ < form ng-submit ="vm.search() ">
2
+ < input type ="search " name ="search " ng-model ="vm.term ">
3
+ < button > Search</ button >
4
+ </ form >
5
+
6
+ < table ng-show ="vm.searchResults.length ">
7
+ < thead >
8
+ < tr >
9
+ < th > Name</ th >
10
+ < th > Phone</ th >
11
+ < th > Address</ th >
12
+ </ tr >
13
+ </ thead >
14
+ < tbody >
15
+ < tr ng-repeat ="person in vm.searchResults ">
16
+ < td > {{person.name}}</ td >
17
+ < td > {{person.phone}}</ td >
18
+ < td > {{person.address.street}}< br />
19
+ {{person.address.city}}, {{person.address.state}} {{person.address.zip}}
20
+ </ td >
21
+ </ tr >
22
+ </ tbody >
23
+ </ table >
Original file line number Diff line number Diff line change
1
+ ( function ( ) {
2
+ 'use strict' ;
3
+
4
+ angular
5
+ . module ( 'myApp' )
6
+ . factory ( 'SearchService' , SearchService ) ;
7
+
8
+ SearchService . $inject = [ '$resource' ] ;
9
+
10
+ function SearchService ( $resource ) {
11
+ var Search = $resource ( '/api/search/people.json' ) ;
12
+
13
+ Search . search = function ( term , callback ) {
14
+ Search . query ( function ( response ) {
15
+ var results = response . filter ( function ( item ) {
16
+ return JSON . stringify ( item ) . toLowerCase ( ) . includes ( term . toLowerCase ( ) ) ;
17
+ } ) ;
18
+ return callback ( results ) ;
19
+ } ) ;
20
+ } ;
21
+
22
+ return Search ;
23
+ }
24
+ } ) ( ) ;
Original file line number Diff line number Diff line change
1
+ ( function ( ) {
2
+ 'use strict' ;
3
+
4
+ angular . module ( 'myApp' )
5
+ . config ( stateConfig ) ;
6
+
7
+ stateConfig . $inject = [ '$stateProvider' ] ;
8
+
9
+ function stateConfig ( $stateProvider ) {
10
+ $stateProvider
11
+ . state ( 'search' , {
12
+ url : '/search' ,
13
+ templateUrl : 'search/search.html' ,
14
+ controller : 'SearchController' ,
15
+ controllerAs : 'vm'
16
+ } ) ;
17
+ }
18
+ } ) ( ) ;
Original file line number Diff line number Diff line change 8
8
"dependencies" : {
9
9
"angular" : " ~1.5.0" ,
10
10
"angular-loader" : " ~1.5.0" ,
11
+ "angular-resource" : " ~1.5.0" ,
11
12
"angular-mocks" : " ~1.5.0" ,
12
13
"html5-boilerplate" : " ^5.3.0" ,
13
14
"angular-ui-router" : " ^0.3.1"
You can’t perform that action at this time.
0 commit comments