[英]url routing on checkbox is checked in angularjs
選擇單選按鈕時,我們可以更改URL嗎? 我正在使用angularjs?
以下是我的代碼,當我選擇輸入單選框時,我想更改網址
<div class="switch">
<input type="radio" class="switch-input" name="view" value="week" id="week" checked>
<label for="week" class="switch-label switch-label-off">
Automatically
</label>
<input type="radio" class="switch-input" name="view" value="month" id="month">
<label for="month" class="switch-label switch-label-on">
Manually
</label>
<span class="switch-selection">
</span>
</div>
在AngularJS中,您可以使用$location
服務將路徑更改為:
$location.path('/new-route');
然后,在input
標簽上,您可以使用ng-change
或ng-click
指令來調用將更改路線的函數。 因此,可能是這樣的:
<input type="radio" ng-click="changeLocation('route-name')>
您的控制器具有以下代碼:
$scope.changeLocation = function (newRoute) {
$location.path(newRoute);
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.