AngularJS : Pass $scope variable as directive attribute

后端 未结 4 1838
失恋的感觉
失恋的感觉 2021-02-13 14:27

I\'m trying to pass the $scope variable values to a custom directive as attribute, but it\'s not working.

Here is the HTML code:

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-13 15:12

    I suppose what you want to do is injecting scope object from controller to your directive. So you can define your directive as

    app.directive('checkList',function(){
        return {
            restrict:'E',
            scope: {
              name: "="
            }
            template: '{{name}}
    Yes
    No', link:function(scope,elem,attrs){ } }; }

    And in your view, you can reference your directive as

    
    

提交回复
热议问题