Pretty new to Angular and quite excited about it. My question is related to one of the older posts.i.e about having different controllers sharing a single model. Basically what I want to achieve is a screen showing two views of the same model.
Suppose you maintain a model which contains width and height. If I want to show two views simultaneously for the same model. One view is actually a drawn rectangle which shows the width, height etc visually. The other view is something like a text view, with input fields bound to this model. Changing the Input fields -> change model -> change the other view.
Now since these 2 views are going to grow big ( in terms of behaviour ), it would be better for organization to put them into 2 different controllers! I want to share the same model between the 2. So this is what I am doing for it.
<!doctype html>
<html ng-app>
<head>
<script type="text/javascript">
var master = {width:200,height:100};
function AlbumCtrl($scope)
{
$scope.master = master;
$scope.mystyle = { display:"block", "background-color" : "#333333", width : master.width + 'px', height: master.height + 'px' };
}
function EditCtrl($scope)
{
$scope.master = master;
}
</script>
<!-- Le styles -->
<link href="assets/css/bootstrap.css" rel="stylesheet">
<link href="assets/css/bootstrap-responsive.css" rel="stylesheet">
<link href="assets/css/docs.css" rel="stylesheet">
<link href="assets/js/google-code-prettify/prettify.css" rel="stylesheet">
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<![endif]-->
<!-- Le fav and touch icons -->
<link rel="shortcut icon" href="assets/ico/favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">
</head>
<body>
<div style="position:relative;display: block;width: auto; height: 300px; background-color: #CCC;" ng-controller="AlbumCtrl">
<div ng-style="mystyle"></div>
</div>
<div ng-controller="EditCtrl">
<form class="form-horizontal">
Width : <input type="text" ng-model="master.width">
Height : <input type="text" ng-model="master.height">
</form>
</div>
</body>
</html>
Everything works except for the style not getting updated. Can someone point to me what I am doing wrong here? Or should this be achieved differently ?