setting model properties from a directive
HTML
<script src="http://code.angularjs.org/1.0.0/angular-1.0.0.min.js"></script>
<div ng-app='myApp'>
<div test ng-model="thisModel" set-to="This Value"></div>
<div test ng-model="thatModel" set-to="That Value"></div>
<hr>
model: {{thisModel}}
model2: {{thatModel}}
</div>
JavaScript
var myApp = angular.module('myApp',[])
.directive("test", function() {
return {
template: '<button>Set value</button>',
require: 'ngModel',
link: function(scope, iElement, iAttrs, ngModel) {
iElement.click(function() {
scope.$apply(function() {
ngModel.$setViewValue(iAttrs.setTo);
});
});
}
};
});