Skip to content

Instantly share code, notes, and snippets.

@murphysean
Last active August 29, 2015 14:05
Show Gist options
  • Save murphysean/6dcec6b89014a888c36d to your computer and use it in GitHub Desktop.
Save murphysean/6dcec6b89014a888c36d to your computer and use it in GitHub Desktop.
Angular Binding to Factory Value
<!doctype html>
<html lang="en" ng-app="testing">
<head>
<meta charset="utf-8">
<title>Angular Binding From Controller to Service(Factory)</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.19/angular.js"></script>
</head>
<body>
<section ng-controller="TestController">
<p>{{rwObject.name}}</p>
</section>
<section ng-controller="TestController">
<input type="text" ng-model="rwObject.name">
</section>
<script>
angular.module("testing",[])
.controller('TestController',['$scope','rwObject', function TestController($scope, rwObject){
$scope.rwObject = rwObject;
}])
.factory('rwObject', [function clientIdFactory(){
var rwObject = new Object();
rwObject.name = "Sean Murphy"
return rwObject;
}]);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment