Skip to content

Commit 6d09cfb

Browse files
author
Nguyen Sy Thanh Son
committed
add ajax sample
1 parent ba9d5c2 commit 6d09cfb

File tree

6 files changed

+129
-0
lines changed

6 files changed

+129
-0
lines changed

app/scripts/app.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ angular
9393
}
9494
}
9595
})
96+
.state('dashboard.ajax',{
97+
url:'/ajax',
98+
controller: 'SampleCtrl',
99+
templateUrl:'views/sample.html',
100+
resolve: {
101+
loadMyFiles:function($ocLazyLoad) {
102+
return $ocLazyLoad.load({
103+
name:'sbAdminApp',
104+
files:[
105+
'scripts/controllers/sample.js',
106+
'scripts/services/sample.js'
107+
]
108+
})
109+
}
110+
}
111+
})
96112
.state('dashboard.form',{
97113
templateUrl:'views/form.html',
98114
url:'/form'

app/scripts/controllers/sample.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
/**
3+
* @ngdoc function
4+
* @name sbAdminApp.controller:MainCtrl
5+
* @description
6+
* # MainCtrl
7+
* Controller of the sbAdminApp
8+
*/
9+
angular.module('sbAdminApp')
10+
.controller('SampleCtrl', function($scope,$position, Sample) {
11+
Sample.get().then(function(data){
12+
$scope.users = data
13+
})
14+
});

app/scripts/directives/sidebar/sidebar.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
<li ui-sref-active="active">
1414
<a ui-sref="dashboard.table"><i class="fa fa-table fa-fw"></i> Tables</a>
1515
</li>
16+
<li ui-sref-active="active">
17+
<a ui-sref="dashboard.ajax"><i class="fa fa-table fa-fw"></i> Ajax Sample</a>
18+
</li>
1619
<li ui-sref-active="active">
1720
<a ui-sref="dashboard.form"><i class="fa fa-edit fa-fw"></i> Forms</a>
1821
</li>

app/scripts/services/sample.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
angular.module('sbAdminApp').factory('Sample', function($http, $q) {
2+
return {
3+
get: function(){
4+
var deferred = $q.defer();
5+
$http.get('scripts/services/sample.json').success(function(data) {
6+
deferred.resolve(data)
7+
}).error(deferred.reject);
8+
return deferred.promise;
9+
}
10+
}
11+
});

app/scripts/services/sample.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[{
2+
"id": "1",
3+
"firstname": "Nguyen Sy",
4+
"lastname": "Thanh Son",
5+
"username": "thanhson1085"
6+
},
7+
{
8+
"id": "2",
9+
"firstname": "Mark",
10+
"lastname": "Otto",
11+
"username": "mdo"
12+
},
13+
{
14+
"id": "3",
15+
"firstname": "Athony",
16+
"lastname": "Vinc",
17+
"username": "anthony"
18+
},
19+
{
20+
"id": "4",
21+
"firstname": "Do",
22+
"lastname": "Minh Khai",
23+
"username": "minhkhai"
24+
},
25+
{
26+
"id": "5",
27+
"firstname": "Ba Ngoc",
28+
"lastname": "Cuong",
29+
"username": "bangoccuong"
30+
},
31+
{
32+
"id": "6",
33+
"firstname": "Adam",
34+
"lastname": "East",
35+
"username": "adam"
36+
},
37+
{
38+
"id": "7",
39+
"firstname": "Larry",
40+
"lastname": "Bird",
41+
"username": "larry"
42+
}]

app/views/sample.html

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<div class="row">
2+
<div class="col-lg-12">
3+
<h1 class="page-header">Tables</h1>
4+
</div>
5+
<!-- /.col-lg-12 -->
6+
</div>
7+
<!-- /.row -->
8+
<div class="row">
9+
<div class="col-lg-12">
10+
<div class="panel panel-default">
11+
<div class="panel-heading">
12+
Basic Table
13+
</div>
14+
<!-- /.panel-heading -->
15+
<div class="panel-body">
16+
<div class="table-responsive">
17+
<table class="table">
18+
<thead>
19+
<tr>
20+
<th>#</th>
21+
<th>First Name</th>
22+
<th>Last Name</th>
23+
<th>Username</th>
24+
</tr>
25+
</thead>
26+
<tbody ng-repeat="user in users">
27+
<tr>
28+
<td>{{ user.id }}</td>
29+
<td>{{ user.firstname }}</td>
30+
<td>{{ user.lastname }}</td>
31+
<td>@{{ user.username }}</td>
32+
</tr>
33+
</tbody>
34+
</table>
35+
</div>
36+
<!-- /.table-responsive -->
37+
</div>
38+
<!-- /.panel-body -->
39+
</div>
40+
<!-- /.panel -->
41+
</div>
42+
<!-- /.col-lg-6 -->
43+
</div>

0 commit comments

Comments
 (0)