2017-06-16 44 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 –