如何在下面执行页路由的匹配媒体。也就是说,如果是平板电脑,我想在家里加载一个不同的templateURL?
app.config(['$routeProvider',function($routeProvider) {
//configure the routes
$routeProvider
.when('/',{
// route for the home page
templateUrl:'partials/login/login.html',
controller:'loginCtrl'
})
.when('/home',{
// route for the home page
templateUrl:'partials/home/home.html',
controller:'mainCtrl'
})
.otherwise({
//when all else fails
templateUrl:'partials/login/login.html',
controller:'loginCtrl'
});
}]);发布于 2015-04-14 11:51:28
您只需在生成templateUrl时添加函数,然后返回templateUrl来检查导航器字符串和浏览器,就可以实现这一点。
码
$routeProvider
.when('/', {
// route for the home page
templateUrl: function() {
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
return 'partials/mobile/login/login.html'; //mobile template
} else {
return 'partials/login/login.html';
}
},
controller: 'loginCtrl'
})https://stackoverflow.com/questions/29626431
复制相似问题