On Github minznerjosh / ember-angular-presentation
Software Engineer @ Cinema6
Browser apps, online video, AngularJS.
<body ng-app> <h4>My title: {{title}}</h4> <form action=""> <input type="text" ng-model="title"> </form> </body>
var App = Ember.Application.create();
<h4>My Title: {{title}}</h4> <form action=""> {{input value=title}} </form>
<body ng-app ng-controller="AppController as AppCtrl"> <h4>What's up, {{name}}?</h4> <button ng-click="AppCtrl.sayName('Josh')">Say My Name</button> </body>
function AppController($scope) { $scope.name = 'Nobody'; this.sayName = function(name) { $scope.name = name; } }
<h4>What's up, {{name}}?</h4> <button {{action "sayName" "Josh"}}>Say My Name</button>
var App = Ember.Application.create(); App.ApplicationController = Ember.Controller.extend({ name: 'Nobody', actions: { sayName: function(name) { this.set('name', name); } } });
<body ng-app ng-controller="AppController as AppCtrl"> <h4>My Title: {{title}}</h4> <form action=""> <input type="text" ng-model="title"> </form> <ul class="list-of-bs"> <li ng-repeat="model in list">{{model.value}}</li> </ul> <button ng-click="AppCtrl.upset()">GO NUTS!</button> <button ng-click="list.length = 0">Clean Up</button> </body>
function AppController($scope) { $scope.list = []; this.upset = function() { for (var index = 0; index < 20000; index++) { $scope.list.push({ value: index }); } }; }
<h4>My Title: {{title}}</h4> <form action=""> {{input value=title}} </form> <ul class="list-of-bs"> {{#each list}} <li>{{this.value}}</li> {{/each}} </ul> <button {{action "upset"}}>GO NUTS!</button> <button {{action "cleanUp"}}>Clean Up</button>
var App = Ember.Application.create(); App.ApplicationController = Ember.Controller.extend({ list: [], actions: { upset: function() { for (var index = 0; index < 20000; index++) { this.list.pushObject({ value: index }); } }, cleanUp: function() { this.list.clear(); } } });
angular.module('app', []) .service('Useless', function($timeout) { this.dumb = function() { $timeout(function() { alert('TROLL'); }, 1000); } }) .controller('AppController', function(Useless) { this.doSomethingDumb = function() { Useless.dumb(); }; });
var Useless = Ember.Object.extend({ dumb: function() { Ember.run.later(null, function() { alert('TROLL'); }, 1000); } }); Ember.Application.initializer({ name: 'registerDep', initialize: function(container, application) { application.register('service:dumb', Useless); } }); Ember.Application.initializer({ name: 'injectDep', after: 'registerDep', initialize: function(container, application) { application.inject('controller:application', 'useless', 'service:dumb'); } }); var ApplicationController = Ember.Controller.extend({ doSomethingDumb: function() { this.useless.dumb(); } });
describe('AppController', function() { var $rootScope, $scope, $controller, AppCtrl; var Useless; beforeEach(function() { module('app', function($provide) { $provide.value('Useless', { dumb: jasmine.createSpy() }); }); inject(function($injector) { $rootScope = $injector.get('$rootScope'); $controller = $injector.get('$controller'); Useless = $injector.get('Useless'); $scope = $rootScope.$new(); AppCtrl = $controller('AppController', { $scope: $scope }); }); }); it('should call dumb() on Useless when its doSomethingDumb() method is called', function() { AppCtrl.doSomethingDumb(); expect(Useless.dumb).toHaveBeenCalled(); }); });
describe('AppController', function() { var appCtrl; var useless; beforeEach(function() { useless = { dumb: jasmine.createSpy() }; appCtrl = App.ApplicationController.create({ useless: useless }); }); it('should call dumb() on Useless when its doSomethingDumb() method is called', function() { appCtrl.doSomethingDumb(); expect(useless.dumb).toHaveBeenCalled(); }); });
<body ng-app="app"> <h3>{{title}}</h3> <blink ng-click="title = 'foo'">Hello!</blink> </body>
angular.module('app', []) .directive('blink', function($timeout) { return { restrict: 'E', scope: {}, link: function(scope, element) { function show() { element.css('display', ''); $timeout(hide, 1000); } function hide() { element.css('display', 'none'); $timeout(show, 1000); } show(); } }; });
<!-- application.hbs --> {{#io-blink}}Hello!{{/io-blink}} <!-- components/io-blink.hbs --> {{yield}}
var App = Ember.Application.create(); App.IoBlinkComponent = Ember.Component.extend({ show: function() { this.$().show(); Ember.run.later(this, this.hide, 1000); }.on('didInsertElement'), hide: function() { this.$().hide(); Ember.run.later(this, this.show, 1000); } });
angular.module('app', ['ngRoute']) .config(function($routeProvider) { $routeProvider .when('/', { controller: 'IndexController', controllerAs: 'IndexCtrl', templateUrl: 'views/index.html' }) .when('/posts', { controller: 'PostsController', controllerAs: 'PostsCtrl', templateUrl: 'views/posts.html' }); });
<h1>My App</h1> <ng-view></ng-view>
var App = Ember.Application.create(); App.Router.map(function() { // /posts this.resource('posts', function() { // /posts/new this.route('new'); }); });
<!-- application.hbs --> <h1>My App</h1> {{outlet}} <!-- posts.hbs --> <h1>My Posts</h1> {{outlet}} <!-- posts/new.hbs --> <h1>New Post</h1>
Do you want to spend your time building the framework, or learning the framework?