Created
July 18, 2014 15:11
-
-
Save Tom-Millard/7cd91060279f8a23afe6 to your computer and use it in GitHub Desktop.
This file contains 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 src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<br /> | |
<br /> | |
<br /> | |
<div ng-controller="container"> | |
<span ng-repeat="(key,value) in items" ng-controller="item"> | |
{{value.id}} - {{value.name}}<br /> | |
</span> | |
</div> | |
<div ng-controller="update"> | |
<input type="text" ng-model="words"></input><br /> | |
<button ng-click="updateFire()">update (target 1)</button> | |
</div> | |
</body> | |
</html> |
This file contains 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 app = angular.module("app", []); | |
app.controller("container", ["$scope", function($scope){ | |
var items = []; | |
items.push({id : 1, name : "hello"}); | |
items.push({id : 2, name : "world"}); | |
$scope.items = items; | |
}]); | |
app.controller("item", ["$scope", "$rootScope",function($scope, $rootScope){ | |
$rootScope.$on("updateItem", function(event, data){ | |
for(var x = 0; x != $scope.items.length; $x++){ | |
if($scope.items[x].id == 1){ | |
$scope.items[x].name = data.value; | |
} | |
} | |
}); | |
}]); | |
app.controller("update", ["$scope", "$rootScope", function($scope, $rootScope){ | |
$scope.updateFire = function(){ | |
$rootScope.$emit("updateItem", {value : $scope.words}); | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment