0

I have a plunk at http://plnkr.co/PF7cRQE4n5lYube8oa3t

The templateUrl points to control.html with the following code.

hello from Directive
<br />{{message}}
<br />
<input type="checkbox" {{checkedstatus}} />
<br />Value of Checked Status = {{checkedstatus}}

My controller and directive is as 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 be checked... no?";
      scope.checkedstatus = "checked";
    }

    return {
      restrict: 'E',
      templateUrl: "control.html",
      link: linkFunction,
      scope: {}
    };
  })

My index.html file is straight forward and is using the directive...

<my-dir></my-dir>

I was assuming that if checkedstatus is set to "checked" I will see the checkbox as checked in the UI. But it doesn't happen that way and remains unchecked. My goal is to use this Checkbox as a toggle button to view or hide certain elements of my view.

1

1 Answer 1

2

you can use ng-checked

scope.checkbox={
    checkedstatus:true
};

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

Or you can bind model

like this

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

Check on plunkr

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

Sign up to request clarification or add additional context in comments.

1 Comment

I have attached the link of plunkr

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.