AngularJS Two-way Data Binding in Nested Directives

前端 未结 3 1028
北海茫月
北海茫月 2021-02-20 05:50

Please let me know if you need more information or want me to clarify anything. I have tried a lot of different things to figure this out but haven\'t found a solution.

3条回答
  •  余生分开走
    2021-02-20 06:24

    Since the textbox in the directive uses a primitive instead of an object for its model (ng-model="value" rather than ng-model="someobj.somevalue"), its model is created only on the local scope and the parent does not have access to it.

    The fix is to define the directive textbox model using the dot rule as an object property:

    ng-model="value.firstname"
    

    Then pass the whole user object into the directive instead of just the primitive property:

    Here is a demo

提交回复
热议问题