我在下面收到错误,但我不明白为什么。有什么想法吗?
HTML,
<button ng-click="loadForm()">Load Directive Form</button>
<div data-my-form></div>
角,
app.directive('myForm', function() {
return {
replace:true,
controller:function($scope){
$scope.isLoaded = false;
$scope.loadForm = function(){
$scope.isLoaded = true;
}
},
template: '<div ng-if="isLoaded" ng-include="\'form.php\'" ></div>',
link:function(scope, element) {
}
}
});
误差,
Error: [$compile:multidir] Multiple directives [ngInclude, ngInclude] asking for transclusion on: <div data-my-form="" ng-if="isLoaded" ng-include="'form.php'">
修复,
'<div><div ng-if="isLoaded" ng-include="\'form.php\'" ></div></div>'
但为什么我必须在div中换行呢?这是一个有角色的错误吗?
答案 0 :(得分:8)
错误很明显。试图使用包含的同一元素有两个指令:
1. ng-if
2. ng-include
元素只能应用一次翻译。
要修复,请尝试以下方法:
<div data-my-form="" ng-if="isLoaded">
<div ng-include="'form.php'"> </div>
</div>