Checkbox not binding to scope in angularjs

前端 未结 4 959
旧时难觅i
旧时难觅i 2020-12-01 01:34

I am trying to bind a checkbox to scope using ng-model. The checkbox\'s initial state corresponds to the scope model just fine, but when I check/uncheck the checkbox, the m

4条回答
  •  没有蜡笔的小新
    2020-12-01 02:21

    In my directive (in the link function) I had created scope variable success like this:

    link: function(scope, element, attrs) {
                "use strict";
    
                scope.success = false;
    

    And in the scope template included input tag like:

    
    

    This did not work.

    In the end I changed my scope variable to look like this:

    link: function(scope, element, attrs) {
                "use strict";
    
                scope.outcome = {
                    success : false
                };
    

    And my input tag to look like this:

    
    

    It now works as expected. I knew an explanation for this, but forgot, maybe someone will fill it in for me. :)

提交回复
热议问题