Created
February 13, 2014 10:31
-
-
Save pvdz/8972923 to your computer and use it in GitHub Desktop.
Fugly angular
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
| <!doctype html> | |
| <html ng-app="app"> | |
| <head> | |
| <script defer src="bootstrap/js/jquery.2.1.0.js"></script> | |
| <script src="angular/angular.1.2.11.min.js"></script> | |
| </head> | |
| <body> | |
| <script> | |
| var app = angular.module('app', []) | |
| .factory('Model', function(){ return {foo: {bar: 'initial'}}; }) | |
| .controller('A', ['$scope', 'Model', function($scope, Model){ | |
| $scope.swap = function(){ Model.foo = {bar: Math.random() }; }; | |
| }]) | |
| .controller('B', ['$scope', 'Model', function($scope, Model){ | |
| $scope.model = Model; | |
| $scope.update = function(){ document.querySelector('input').value += 'px'; }; | |
| }]); | |
| </script> | |
| <div> | |
| <div ng-controller="A"> | |
| <button ng-click="swap();">Swap!</button> | |
| </div> | |
| <div ng-controller="B"> | |
| <!-- i only want one way binding here! so updating the input should NOT modify the model --> | |
| <input value="{{model.foo.bar}}"> <button ng-click="update();">add pixels!</button> | |
| </div> | |
| </div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment