Binding a checkbox in Angularjs in Directive -


i have plunk @ http://plnkr.co/pf7crqe4n5lyube8oa3t

the templateurl points control.html following code.

hello directive <br />{{message}} <br /> <input type="checkbox" {{checkedstatus}} /> <br />value of checked status = {{checkedstatus}} 

my controller , directive follows...

var app = angular.module('plunker', []);  app.controller('mainctrl', function($scope) {   $scope.name = 'world'; })   .directive('mydir', function() {     var linkfunction = function(scope, element, attributes){       scope.message = "the check box should checked... no?";       scope.checkedstatus = "checked";     }      return {       restrict: 'e',       templateurl: "control.html",       link: linkfunction,       scope: {}     };   }) 

my index.html file straight forward , using directive...

<my-dir></my-dir> 

i assuming if checkedstatus set "checked" see checkbox checked in ui. doesn't happen way , remains unchecked. goal use checkbox toggle button view or hide elements of view.

you can use ng-checked

scope.checkbox={     checkedstatus:true };  <input type="checkbox" ng-checked="checkbox.checkedstatus" /> 

or can bind model

like

<input type="checkbox" ng-model="checkbox.checkedstatus" /> 

check on plunkr

http://plnkr.co/edit/qkwyqrlbwykv1ecz0whe?p=preview


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -