-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibro.factory.js
More file actions
55 lines (43 loc) · 1.25 KB
/
Libro.factory.js
File metadata and controls
55 lines (43 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
(function(){
'use strict';
angular
.module( 'helloApp' )
.factory( 'Libro',fLibro);
fLibro.$inject=['$http'];
function fLibro( $http ){
Libro.prototype = {
load: load,
setData:setData,
remove:remove,
update:update,
isAvailable:isAvailable
};
return Libro;
function Libro(){}; //As you can see, the controller became very thin. It now creates a Book instance, assigns it
//to the scope and loads it from the backend. When the book will be loaded, it’s properties
//will be changed and so the template. Keep in mind that other controllers that interact with
//a book, simply inject the Book service.
function setData( _jsonBookData ){
angular.extend( this,_jsonBookData );
};
function load(){
var url = 'http://www.mocky.io/v2/583664bb1100006b190c00a1?callback=JSON_CALLBACK';
var _scope=this;
$http.jsonp( url ).success( function( jsonBookData ) {
_scope.setData( jsonBookData );
});
};
function remove(){
alert( "Se ha invocado el borrado" );
};
function update(){
alert( "Se ha invocado el Update" );
};
function isAvailable(){
if ( !this.stores || this.stores.length === 0 ) {
return false;
}
return ( this.stores.length>0 );
};
};
})();