我想在AngularJS中使用$locationProvider
服務,而無需在我的ng-view
中呈現新的HTML模板。
我有一個div
元素,通過ng-show
按需顯示綁定到一個數據元素的存在。我想通過$locationProvider
將其連接到瀏覽器位置,但保持在同一模板中。
模板:
<div> other stuff ... </div>
<div ng-show="model">{{ model.element }}</div>
控制器:
Controller = function($scope, $location) {
$scope.show = function() {
$scope.model = model; // show div
}
$scope.hide = function() {
$scope.model = null; // hide div
}
}
我無法弄清楚如何將$location
服務在這個整合。如果直接設置了history.pushState
,AngularJS也會覆蓋該位置。
謝謝,這是行不通的。我在這個解決方案中使用它:http://stackoverflow.com/a/15169779/215945 –