Skip to content

Instantly share code, notes, and snippets.

@pvdz
Created February 13, 2014 10:31
Show Gist options
  • Select an option

  • Save pvdz/8972923 to your computer and use it in GitHub Desktop.

Select an option

Save pvdz/8972923 to your computer and use it in GitHub Desktop.
Fugly angular
<!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