1
- 爲什麼
myFilter
調用的$scope.currentLanguageId
English()
或France()
函數值後不會改變? - 是通過過濾器進行網站的不同本地化的正常方法嗎?或者現有可能是更常見的方式?
<div ng-init="GetList()">
<div ng-repeat="item in items | filter: myFilter">
{{item.Text}} {{item.LanguageId}}
</div>
</div>
菜單:
<div class="menu">
<ul>
<li><a href="#/about">About</a></li>
<li><a href="#/contacts">Contacts</a></li>
<li><a>Test</a></li>
<li><a>Test</a></li>
<li><a>Test</a></li>
<li><input type="button" value="En" ng-controller="homeController" ng-click="English()" /></li>
<!--<li><a>En</a></li>
<li><a>Fr</a></li>-->
</ul>
</div>
控制器:
app.controller('homeController', function ($scope, $http) {
$scope.items = [];
$scope.currentLanguageId = '';
$scope.GetList = function() {
$http({
method: 'GET',
url: '/Home/GetList',
params: { languageId: '1'}
}).then(function successCallback(response) {
$.each(response.data, function (id,item) {
$scope.items.push({ Text: item.Text, LanguageId: item.LanguageId });
});
}, function errorCallback(response) {
alert('Error');
});
}
$scope.English = function() {
$scope.currentLanguageId = '2';
}
$scope.France = function() {
$scope.currentLanguageId = '3';
}
$scope.myFilter = function (item) {
console.log($scope.currentLanguageId);
return item.LanguageId == $scope.currentLanguageId;
};
});
我已經親自使用了angular-translate(i18n),我認爲這些東西你也可以看一下:https://angular-translate.github.io/ – thepio