Merge pull request #11 from nicholasess/gh-pages

add service and directive in file angularjs.md
This commit is contained in:
Rico Sta. Cruz 2015-05-12 14:09:59 +08:00
commit b0f23d3c80
1 changed files with 27 additions and 0 deletions

View File

@ -42,6 +42,33 @@ layout: default
($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