This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.controller('MainCtrl', ['$scope', '$timeout', function($scope, $timeout){ | |
| $timeout(function() { | |
| console.log($scope); | |
| }); | |
| }]); | |
| //another best bractice approach with $inject | |
| app.controller('MainCtrl', mainCtrl); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var underscore = angular.module('underscore', []); | |
| underscore.factory('_', function() { | |
| return window._; //Underscore must already be loaded on the page | |
| }); | |
| var app = angular.module('app', ['underscore']); | |
| app.controller('MainCtrl', ['$scope', '_', function($scope, _) { | |
| init = function() { | |
| _.keys($scope); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.value('a', 123); | |
| module.constant('A', 321); //can't modify with a decorator | |
| function Controller(a, A) { | |
| expect(a).toEqual(123); | |
| expect(A).toEqual(231); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.factory('b', function(a) { | |
| return a*2; | |
| }); | |
| function Controller(b) { | |
| expect(b).toEqual(246); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.factory('greeterFactory', function(a) { | |
| function Greeter(a) { | |
| this.greet = function() { | |
| return 'Hello ' + a; | |
| } | |
| } | |
| return new Greeter(a); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.provider('greeter3', function() { | |
| var salutation = 'Hello'; | |
| this.setSalutation = function(s) { | |
| salutation = s; | |
| } | |
| function Greeter(a) { | |
| this.greet = function() { | |
| return salutation + ' ' + a; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.service = function(name, Class) { | |
| provider.provide(name, function() { | |
| this.$get = function($injector) { | |
| return $injector.instantiate(Class); | |
| }; | |
| }); | |
| } | |
| module.factory = function(name, factory) { | |
| provider.provide(name, function() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div ng-controller="navCtrl"> | |
| <span>{{user}}</span> <!-- won't be updating --> | |
| <div ng-controller="loginCtrl"> | |
| <span>{{user}}</span> | |
| <input ng-model="user"></input> <!-- changes update only loginCtrl scope --> | |
| </div> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div ng-controller="navCtrl"> | |
| <span>{{user.name}}</span> | |
| <div ng-controller="loginCtrl"> | |
| <span>{{user.name}}</span> | |
| <input ng-model="user.name"></input> | |
| </div> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var animal = { eats: true }, | |
| rabbit = { jumps: true }; | |
| rabbit.__proto__ = animal; | |
| console.log(rabbit.eats) //true |