Passing ng-model in nested directives

前端 未结 2 965
我在风中等你
我在风中等你 2021-02-02 07:39

I want to pass my ng-model from the \'outer-directive\' to an \'inner-diretive\' (which is contained in the outer-directive template).

What is the correct way for doing

相关标签:
2条回答
  • 2021-02-02 07:50

    I think you need to pass the form in the directive and set the form dirty manually.

    <directive directive-form="editForm" ></directive>
    
    scope: {
     directiveForm:"="
     },
     link: function (scope, $elem, $attrs){
      scope.directiveForm.$setDirty(); 
     }
    
    0 讨论(0)
  • 2021-02-02 07:53

    You can set up a bi-directional binding (see the documentation, section "Directive Definition Object") with the variable in ngModel attribute, as with any other directives:

    <my-directive ng-model="foo"></my-directive>
    
    myApp.directive('myDirective', function () {
        return {
            template: '<div><input type="text" ng-model="ngModel" /></div>',
            replace: true,
            scope: {
                ngModel : '=',
            },
        };
    });
    

    Fiddle

    0 讨论(0)
提交回复
热议问题