我的选择如下:
<select onchange="getVideo()" id="region">
<option ng-repeat="items in region" ng-selected = "items.countryCode === selectedRegion" value="{{items.countryCode}}">{{items.countryCode}}</option>
</select>
这是我的JSON:
$scope.region = [
{
countryItem : "TW(TW)",
countryCode : "tw_zh_tw"
},
{
countryItem : "US(EN)",
countryCode : "us_en"
},
{
countryItem : "US(ES)",
countryCode : "us_es"
},
{
countryItem : "JP(JA)",
countryCode : "jp_ja"
},
];
当选择框改变时,它将调用一个getVideo()函数函数:
function getVideo() {
var language = $("#region option:selected").val();
location.href="/support/"+language+"/Videobackstage;
}
使用此功能,页面总是在选择更改时加载,因此即使页面加载,我也需要保留选择的值。
为了解决这个问题,我想出了一个解决方案,我使用文本框ng-model作为ng-select条件的参数,文本框有一个值,它按照我想要的方式工作,但对于选择它不是工作:
<input type="text" ng-model="selectedRegion" id="selectedRegionx">
我通过在网址中获取特定值来设置文本框的值:
$(document).ready(function(){
var pageUrl = window.location.pathname;
var split = pageUrl.split("/");
var langUrl = split[2];
$("#selectedRegionx").val(langUrl);
});
答案 0 :(得分:0)
我创建了可由角度控制器访问的全局变量:
var pageUrl = window.location.pathname;
var split = pageUrl.split("/");
var langUrl = split[2];
我刚在控制器中添加了一个范围:
$scope.selectedRegion = langUrl;
现在工作正常!