1
我正在使用角度ui路由器,並且需要根據父級(body
)作用域中的變量爲給定狀態顯示不同的模板。但是當我添加這個$scope.data
條件它不會觸發。我甚至沒有得到console.log()
或任何網址更改。 :(
$stateProvider.state('map1', {
url: "/content/sectionI",
templateProvider: function($scope, $http, $stateParams) {
console.log("Wowie!",$scope.data);
if($scope.data.Section_I_Part_1_Complete == "0")
{
return $http({
method: 'GET',
url: 'http://example.com/contentMore',
params: {
request: "Section_I_Part_1_Complete",
part: "1"
}
}).then(function successCallback(html) {
return html.data;
});
}
else
{
return $http({
method: 'GET',
url: 'http://example.com/contentMore',
params: {
request: "Section_I_Unlocked",
part: "map"
}
}).then(function successCallback(html) {
return html.data;
});
}
},
controller: function($scope) {
$scope.activeSection.activeSection = "notNone";
}
})
我怎麼做,這樣我可以得到模板返回基於變量的父範圍值?
如果我理解正確的話,您要確定動態templateUrl的狀態,您可以通過改變'$ stateChangeStart' templateUrl實現價值即見相關的SO職位:HTTP://計算器。 COM /問題/ 23512238/UI路由器動態模板路徑 –