add service and directive in file angularjs.md
This commit is contained in:
parent
f0bcb06908
commit
498f24c5c5
27
angularjs.md
27
angularjs.md
|
@ -42,6 +42,33 @@ layout: default
|
||||||
($scope, $http) ->
|
($scope, $http) ->
|
||||||
]
|
]
|
||||||
|
|
||||||
|
### Service
|
||||||
|
|
||||||
|
App.factory('NameService', function($http){
|
||||||
|
return {
|
||||||
|
get: function(){
|
||||||
|
return $http.get(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
In controller you call with parameter and will use promises to return data from server.
|
||||||
|
|
||||||
|
App.controller('controllerName',
|
||||||
|
function(NameService){
|
||||||
|
NameService.get()
|
||||||
|
.then(function(){})
|
||||||
|
})
|
||||||
|
|
||||||
|
### Directive
|
||||||
|
|
||||||
|
App.directive('name', function(){
|
||||||
|
return {
|
||||||
|
template: '<h1>Hello</h1>'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
In HTML will use <name></name> to render your template <h1>Hello</h1>
|
||||||
|
|
||||||
### HTTP
|
### HTTP
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue