Javascript 指令,其中包括从属性创建TemplateUrl的页面

Javascript 指令,其中包括从属性创建TemplateUrl的页面,javascript,angularjs,angularjs-directive,Javascript,Angularjs,Angularjs Directive,我有用Angular.js编写的元应用程序,我可以使用Angular创建应用程序,但有一些限制。我可以使用和创建指令,并创建自动添加到$route的页面 我需要指令小部件,它将使用其他页面作为模板,但页面url需要是动态的(基于属性)将包括使用名称属性的模板,以下是我的代码: return { restrict: 'EA', replace: true, transclude: true, compile: function(tElement, tAttrs, t

我有用Angular.js编写的元应用程序,我可以使用Angular创建应用程序,但有一些限制。我可以使用和创建指令,并创建自动添加到$route的页面

我需要指令
小部件
,它将使用其他页面作为模板,但页面url需要是动态的(基于属性)
将包括使用
名称
属性的模板,以下是我的代码:

return {
    restrict: 'EA',
    replace: true,
    transclude: true,
    compile: function(tElement, tAttrs, transclude) {
        this.templateUrl = $route.routes['/<APP-NAME>/' + tAttrs.name].templateUrl;
    }
};
返回{
限制:“EA”,
替换:正确,
是的,
编译:函数(远程通讯、tAttrs、转置){
this.templateUrl=$route.routes['/'+tAttrs.name].templateUrl;
}
};

我在想也许我可以使用$http获取模板,但是我可以从编译函数返回承诺以及如何替换模板吗?

templateUrl
可以是一个函数。所以你可以写一些像

function getUrl(tElement, tAttrs) {
  return tAttrs.name;
}

return {
  restrict: 'EA',
  replace: true,
  templateUrl: getUrl
};

Angular获取模板本身

模板URL
可以是一个函数。所以你可以写一些像

function getUrl(tElement, tAttrs) {
  return tAttrs.name;
}

return {
  restrict: 'EA',
  replace: true,
  templateUrl: getUrl
};

Angular获取模板本身

模板URL
可以是一个函数。所以你可以写一些像

function getUrl(tElement, tAttrs) {
  return tAttrs.name;
}

return {
  restrict: 'EA',
  replace: true,
  templateUrl: getUrl
};

Angular获取模板本身

模板URL
可以是一个函数。所以你可以写一些像

function getUrl(tElement, tAttrs) {
  return tAttrs.name;
}

return {
  restrict: 'EA',
  replace: true,
  templateUrl: getUrl
};

Angular获取模板本身

您真的应该提到您使用的是angular 1.06,因为从那以后发生了很大的变化。@zeroflagL我已经在1.2.x版中尝试了您的代码,并且成功了,您应该取消删除答案,我会接受的。很遗憾,我可以用我强制使用的系统。你真是太好了。谢谢。你真的应该提到你使用angular 1.06,因为从那以后发生了很大的变化。@zeroflagL我已经在1.2.x版中尝试了你的代码,它可以工作了,你应该取消删除答案,我会接受的。很遗憾,我可以用我强制使用的系统。你真是太好了。谢谢。你真的应该提到你使用angular 1.06,因为从那以后发生了很大的变化。@zeroflagL我已经在1.2.x版中尝试了你的代码,它可以工作了,你应该取消删除答案,我会接受的。很遗憾,我可以用我强制使用的系统。你真是太好了。谢谢。你真的应该提到你使用angular 1.06,因为从那以后发生了很大的变化。@zeroflagL我已经在1.2.x版中尝试了你的代码,它可以工作了,你应该取消删除答案,我会接受的。很遗憾,我可以用我强制使用的系统。你真是太好了。谢谢