小编jon*_*bro的帖子

在ng-switch中使用ng-transclude

我无法让ng-transclude在ng-switch-default指令中工作.这是我的代码:

指示:

.directive('field', ['$compile', function($complile) {
        return {
            restrict: 'E',
            scope: {
                ngModel: '=',
                type: '@',
            },
            transclude: true,
            templateUrl: 'partials/formField.html',
            replace: true
        };
    }])
Run Code Online (Sandbox Code Playgroud)

谐音/ formField.html

<div ng-switch on="type">
    <input ng-switch-when="text" ng-model="$parent.ngModel" type="text">
    <div ng-switch-default>
        <div ng-transclude></div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我称之为......

<field type="other" label="My field">
    test...
 </field>
Run Code Online (Sandbox Code Playgroud)

哪会产生错误:

[ngTransclude:orphan] Illegal use of ngTransclude directive in the template! No parent directive that requires a transclusion found.
Run Code Online (Sandbox Code Playgroud)

它在ng-switch指令之外毫无障碍地工作,但我对如何使其工作感到茫然.有什么建议?

编辑:这是一个现场演示:http://plnkr.co/edit/3CEj5OY8uXMag75Xnliq?p = preview

javascript angularjs angularjs-directive

5
推荐指数
2
解决办法
2829
查看次数