This lesson describes what's really happening when you use the angular
Factory and how can make your factories even more dynamic in creation.
This gets further to the internals of AngularJS by showing what a factory is built dynamically for you and how they h Ave reduced the plumbing you need and make applications.
Factory:
<!DOCTYPE HTML><HTML><HeadLang= "en"> <MetaCharSet= "Utf-8"> <title>Egghead Videos</title> <Linkrel= "stylesheet"href= "Vendor/foundation/foundation.min.css"></Head><Body> <DivNg-app= "App"Ng-controller= "Appctrl"> <H1class= "Panel">{{title}}</H1> </Div> <Scripttype= "Text/javascript"src= "Https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></Script> <Scripttype= "Text/javascript"src= "App/js/main.js"></Script></Body></HTML>
var app = Angular.module ("app", []); App.factory (function() { return { "StarCraft" }}) App.controller (function($scope, game) { = Game.title});
"App.Factory" is just simply short-hand for using this "provide object":
/**/var app = Angular.module ("app", []); $provide) { $provide. Factory (function() { return{ " StarCraft "}}) }) App.controller (function($scope, game) { = Game.title});
"Factory" is really just shorthand for the provider which sets up a more generic provider which returns things or objects That has the "get" functions:
/** * Created by Answer1215 on 12/27/2014.*/varApp = Angular.module ("app", []); app. Config (function($provide) {$provide. Provider ("Game",function() { return{$get:function() { return{title:"StarCraft"}} ) App.controller ("Appctrl",function($scope, game) {$scope. Title=game.title});
If you want to set up something like game provider and set the type of game:
/** * Created by Answer1215 on 12/27/2014.*/varApp = Angular.module ("app", []); App.provider ("Game",function() { vartype; return{setType:function(title) {type=title; }, $get:function() { return{Title:type+ "Craft"}}}) app. Config (function(Gameprovider) {Gameprovider.settype ("War");}) App.controller ("Appctrl",function($scope, game) {$scope. Title=game.title});
[AngularJS] Provider