2017-06-16 42 views
0

如何角通查询字符串参数组件在angularjs

app.component('test', { 
    templateUrl: '/_directive/test.tpl.html', 
    bindings: { 
    currenttab: "=" 
    }, 
    controllerAs: 'test', 
    controller: test }); 

通过查询字符串参数组件我想是这样的:

templateUrl: '/_directive/test.tpl.html?version=' + version; 

回答

0

不能使用URL作为"/_directive/test.tpl.html" + version,因为会编译到/_directive/test.tpl.html0.0.1而这个html没有找到,所以我们应该将其更改为"/_directive/test.tpl.html?" + version"/_directive/test.tpl.html?version=" + version以获得更好的结果:

/_directive/test.tpl.html?0.0.1 
/_directive/test.tpl.html?version=0.0.1 

在所有我们要设置的主题之前定义的角度应用项目发送的公共参数,可以看到的例子

window.version = "0.0.1"; 

var app = angular.module("app", ["ngRoute"]); 

app.component('test', { 
    templateUrl: 'partials/home-template.html?' + window.version, 
    controller: function() { 
     console.log(window.version) 
    } 
}); 

检查网络标签在火狐看编译模式。

+0

你的回答是对的,但是** templateUrl **不能访问直接值。所以我使用**模板**字段,并使用ng-transclude&fire在控制器上的更改事件 –

+0

正确答案:https://stackoverflow.com/questions/33841909/angular-1-5-component-method-templateurl-功能?noredirect = 1&LQ = 1 –