我有一个带变量类型的指令myDirective.如果我运行,<my-directive type="X">我希望指令使用templateUrl:x-template.html.如果我这样做,<my-directive type="Y">我希望该指令使用templateUrl:y-template.html.
这是我目前的指示.
app.directive('myDirective', function() {
var myDirective = {
templateUrl: 'X-template.html',
restrict: 'E',
scope: {
type: '='
},
};
return myDirective;
});
Run Code Online (Sandbox Code Playgroud)
我通过stackoverflow和angular文档阅读,但没有找到我需要的任何东西.
我现在正试图做一些事情:
if ($scope.type === 'X') {
templateUrl: 'X-template.html',
}
else if ($scope.type === 'Y') {
templateUrl: 'Y-template.html',
}
Run Code Online (Sandbox Code Playgroud)
但不知道在哪里做.
你们知道这是否可行以及如何实现?