Merge pull request #11 from nicholasess/gh-pages
add service and directive in file angularjs.md
This commit is contained in:
commit
b0f23d3c80
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