Angularjs 如何在Angular JS指令中动态更改模板URL?

Angularjs 如何在Angular JS指令中动态更改模板URL?,angularjs,angularjs-directive,Angularjs,Angularjs Directive,我知道有一个很好的选择,但这不是我想要的。ng include允许我动态更改路径,但这样我就无法访问范围变量 基本上,我希望通过AJAX调用动态地将模板URL分配给指令。不幸的是,我似乎无法将指令属性绑定到实际的范围变量 app.directive('appsdirective', function() { return { templateUrl : function(elem,attrs) { // attrs.templateUrl cont

我知道有一个很好的选择,但这不是我想要的。ng include允许我动态更改路径,但这样我就无法访问范围变量

基本上,我希望通过AJAX调用动态地将模板URL分配给指令。不幸的是,我似乎无法将指令属性绑定到实际的范围变量

app.directive('appsdirective', function() {
    return {
        templateUrl : function(elem,attrs) {
            // attrs.templateUrl contains "app.appPath" rather than the content itself
            return attrs.templateUrl;
        },
        restrict : 'EA',
        scope : false
    }
});

<appsdirective template-url="{{app.appPath}}"></appsdirective>
app.directive('appsdirective',function(){
返回{
templateUrl:函数(元素、属性){
//attrs.templateUrl包含“app.appPath”,而不是内容本身
返回attrs.templateUrl;
},
限制:“EA”,
范围:假
}
});

的可能重复-具体使用ng-include检查第二个答案。第二个答案使用我试图避免的ng-include。第一个使用了templateUrl函数,但在当前版本的AngularJS中似乎不起作用。但我不能访问scope变量到底是什么意思?另外,在ajax回调之前使用ng if不渲染也不起作用吗?在指令中,我正在访问许多父控制器变量,但当我使用ng include解决方案时,绑定停止工作。明白了,ng if也不起作用吗?