Dynamic ng-model binding inside a directive

前端 未结 1 1221
春和景丽
春和景丽 2020-12-31 05:40

I\'m trying to create a custom component that uses a dynamic ng-model inside-out the directive.

As an example, I could invoke different components like:



        
相关标签:
1条回答
  • 2020-12-31 05:58

    Something like this?

    http://jsfiddle.net/bateast/RJmhB/1/

    HTML:

    <body ng-app="test">
        <my-dir ng-model="test"></my-dir>
        <input type="text" ng-model="test"/>
    </body>
    

    JS:

    angular.module('test', [])
        .directive('myDir', function() {
            return {
                restrict: 'E',
                scope: {
                    ngModel: '='
                },
                template: '<div><input type="text" ng-model="ngModel"></div>',            
            };
        });
    
    0 讨论(0)
提交回复
热议问题