javascript – Angular指令 – 要求进行翻译?
作者:互联网
我在下面收到错误,我不明白为什么.有任何想法吗?
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?这是一个有角度的错误吗?
解决方法:
错误很明显.尝试使用transclusion的同一元素有两个指令:
1. ng-if
2. ng-include
元素只能应用一个翻译.
要修复,请尝试以下方法:
<div data-my-form="" ng-if="isLoaded">
<div ng-include="'form.php'"> </div>
</div>
标签:html,angular-directive,javascript,php,angularjs 来源: https://codeday.me/bug/20190725/1529122.html