Six stars of AngularJS - Part 2
// sample 1
$provide.factory('movieService', movieService);
function movieService() {
return { // service
getAllMovies: getAllMovies
};
function getAllMovies() {
return ['engMovie1', 'engMovie2', 'engMovie3'];
}
}
// sample 2
var app = angular.module('app');
app.factory('movieService', movieService);
function movieService() {
return { // service
getAllMovies: getAllMovies
};
function getAllMovies() {
return ['engMovie1', 'engMovie2', 'engMovie3'];
}
}
// sample 3
app.service('movieService', movieService);
function movieService() {
this.getAllMovies = getAllMovies;
function getAllMovies() {
return ['engMovie1', 'engMovie2', 'engMovie3'];
}
}
// sample 4
app.value('movieService', movieService()); // Note : function is invoked
function movieService() {
return {
getAllMovies: getAllMovies
}
function getAllMovies() {
return ['engMovie1', 'engMovie2', 'engMovie3'];
}
}
// sample 5
app.value('movieService', { getAllMovies: getAllMovies});
// sample 6
app.value('movieService', "sample service");
// sample 7
app.constant('PI', 3.14);