AngularJS directive transclude scope=false?

前端 未结 2 986
伪装坚强ぢ
伪装坚强ぢ 2021-01-05 08:02

How to prevent directive with transclude to create new scopes?

This jsfiddle I cant bind anything due to the new scopes illustrated with red borders.

相关标签:
2条回答
  • 2021-01-05 09:01

    It is actually expected behavior as stated here (ng-transclude create a child scope): https://github.com/angular/angular.js/issues/1056 and discussed here: https://groups.google.com/forum/#!msg/angular/45jNmQucSCE/hL8x48-JfZIJ

    You can workaround this by setting a member on an object in the scope (obj.var) like in this fiddle: http://jsfiddle.net/rdarder/pnSNj/10/

    0 讨论(0)
  • 2021-01-05 09:01

    Although this is not recommended by the Angular team, another workaround is to explicitly call the $parent scope within the transcluded portion:

    <div ng-app="components">
        <input ng-model="var">
        <block>
            123
            <input ng-model="$parent.var">
        </block>
    </div>
    
    0 讨论(0)
提交回复
热议问题