我想根據屏幕寬度更改siteType
的值,而無需在視圖部分進行編輯。如何根據屏幕寬度加載不同的html?
app.js
'use strict';
var app = angular.module('Location', []).
config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/', { templateUrl: 'pages/' + **params.siteType** + '/locationList.html', controller: Location }).
when('/locationDetail/:projectId', {
templateUrl: function (params) { return 'pages/' + **params.siteType** + '/locationDetail.html'; },
controller: Location
}).
otherwise({ redirectTo: '/' });
}])
app.config(['$locationProvider', function($location) {
$location.hashPrefix('!');
}]);
Controller.js
'use strict';
function Location($scope, $http, $routeParams) {
$scope.projectId = $routeParams.projectId;
$scope.selectedProject = null;
$scope.locationList = null;
$scope.siteType = "desktop";
$(window).resize(function(){
if(window.innerWidth < 600) {
$scope.$apply(function(){
$scope.siteType = "mobile";
});
} else {
$scope.$apply(function(){
$scope.siteType = "desktop";
});
}
});
$http.get("location.json")
.success(function(data){
$scope.locationList = data;
var indexedloc = [];
$scope.locationListToFilter = function(){
indexedloc = [];
return $scope.locationList;
}
$scope.filterLocation = function(Loc){
var locationIsNew = indexedloc.indexOf(Loc.field_data_field_location_field_location) == -1;
if(locationIsNew){
indexedloc.push(Loc.field_data_field_location_field_location);
}
return locationIsNew;
}
$scope.returnFilterLoc = function(){return indexedloc};
if($scope.projectId && $scope.projectId != null) {
for(var i = 0;i < $scope.locationList.length;i++){
if($scope.locationList[i].tid == $scope.projectId) {
$scope.selectedProject = $scope.locationList[i];
}
}
}
})
.error(function(data) {
$("div.category-wrapper").html("Error");
});
}
http://en.wikipedia.org/wiki/Responsive_web_design – ceejayoz 2014-12-05 18:17:17
你應該考慮到http://getbootstrap.com/getting-started/ – Aaron 2014-12-05 23:35:11