AngularJS
Dependencies and Services
AngularJS Dependencies and Services Dependencies & Services - - PowerPoint PPT Presentation
AngularJS Dependencies and Services Dependencies & Services App can get cluttered if all logic in one module Mingling directives and controllers and data in one module can clutter that module Can some logic or data be factored out
Dependencies and Services
module can clutter that module
module?
products.js, for example, and move product related stuff into that module
dependency?
module
functionality, like
to a server
$http({method: 'GET', url: '/products.json'});
$http.get('/products.json', {apiKey: 'myApiKey'});
.then(successCallback, failureCallback) method.
automatically decoded into JavaScript objects and arrays
services they need.
// This uses a funky array syntax: app.controller('SomeController', ['$http', function($http) { // note the listing of the service name and // its usage as an argument to function } ]); // What if you need more than one service? app.controller('SomeController', ['$http' '$log', function($http, $log) { } ]);
and delete()
a config object:
module to create a new service
lifetime spans the execution of the AngularJS app
invocation of the service method
module that is going to use new service module
file
provider/