File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change 10
10
var User = datastore . defineResource ( 'user' ) ;
11
11
12
12
angular . module ( 'firebase-example' , [ ] )
13
- . controller ( 'firebaseCtrl' , function ( $scope ) {
13
+ . controller ( 'firebaseCtrl' , function ( $scope , $timeout ) {
14
14
$scope . add = function ( user ) {
15
- User . create ( user ) ;
15
+ $scope . creating = true ;
16
+ User . create ( user ) . then ( function ( ) {
17
+ $scope . creating = false ;
18
+ $timeout ( ) ;
19
+ } , function ( ) {
20
+ $scope . creating = false ;
21
+ } ) ;
16
22
} ;
17
23
$scope . remove = function ( user ) {
18
- User . destroy ( user . id ) ;
24
+ $scope . destroying = user . id ;
25
+ User . destroy ( user . id ) . then ( function ( ) {
26
+ delete $scope . destroying ;
27
+ $timeout ( ) ;
28
+ } ) ;
19
29
} ;
20
30
$scope . $watch ( function ( ) {
21
31
return User . lastModified ( ) ;
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ <h3 class="panel-title">Users</h3>
23
23
< div class ="list-group ">
24
24
< div class ="list-group-item " data-ng-repeat ="user in users track by user.id ">
25
25
< div class ="pull-right ">
26
- < button class ="btn btn-sm btn-danger " data-ng-click ="remove(user) ">
26
+ < button class ="btn btn-xs btn-danger " data-ng-click ="remove(user) " data-ng-disabled =" destroying === user.id ">
27
27
Delete
28
28
</ button >
29
29
</ div >
@@ -33,7 +33,7 @@ <h3 class="panel-title">Users</h3>
33
33
< form id ="user-form " name ="user-form " data-ng-submit ="add({ name: fCtrl.name }) ">
34
34
35
35
< input class ="form-control " type ="text " data-ng-model ="fCtrl.name " id ="name " name ="name "
36
- placeholder ="Enter a name and press enter "/>
36
+ placeholder ="Enter a name and press enter " data-ng-disabled =" creating " />
37
37
< input type ="submit " class ="hidden "/>
38
38
</ form >
39
39
</ div >
You can’t perform that action at this time.
0 commit comments