I am newbie in angular
I have a directive and a controller. Look in the example What I want is change the checkbox value (true/false) on clicking the text as well as on clicking the outer div the text is in the controller.
Example : https://jsfiddle.net/pdhm98s3/
HTML
<div ng-app="miniapp">
<div ng-controller="myController">
<add-checkbox></add-checkbox>
<div ng-click="changeCheckbox()">
Change Check Value
</div>
</div>
</div>
JS
var app = angular.module('miniapp', []);
app.directive("addCheckbox", function() {
return {
"restrict": "E",
"replace": true,
"scope": true,
"template": '<div><div class="checkContainer"><input type="checkbox" ng-model="checkboxChecked"></div><div>{{!!checkboxChecked}}</div></div>',
"link": function($scope, $elem, attrs) {
$elem.bind("click", function() {
$scope.checkboxChecked = !$scope.checkboxChecked;
})
}
}
})
app.controller("myController", function($scope) {
$scope.changeCheckbox = function() {
$scope.checkboxChecked = !$scope.checkboxChecked;
}
})