Angular: Empty Fiddle
http://angularjs.org/
by Snsa90
HTML
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<div ng-app="myApp" ng-controller="MyCtrl as MC">
{{MC.data[0]}} <br/>
{{MC.data[1]}} <br/>
<strong>THIS DOESN'T MIMIC THE ABOVE :</strong> {{MC.separateData}} <br/>
<strong>THIS DOESN'T MIMIC THE ABOVE :</strong> {{MC.otherData}} <br/>
<my-directive data="MC.data"></my-directive>
</div>
JavaScript
var myApp = angular.module('myApp', []);
//myApp.factory('myService', function() {});
myApp.controller('MyCtrl', MyCtrl);
myApp.directive('myDirective', MyDirective);
function MyCtrl($scope) {
var vm = this;
vm.data = ['data a', 'data b'];
vm.separateData = vm.data[0];
vm.otherData = vm.data[1];
}
function MyDirective() {
return {
template: "<input type='text' ng-model='data[0]' /><br/><input type='text' ng-model='data[1]' />",
scope: { data: '=' },
controller: function($scope) {
}
}
}