用anglajs怎样改变html的url,根据屏幕分辨率AngularJS更改指令的templateUrl

我需要根据屏幕分辨率更改templateURL,例如,如果我的屏幕宽度小于768px,则必须加载“ templates / browse-content-

mobile.html”;如果屏幕宽度大于768px,则必须加载“ templates / browse-content” .html”。

当前使用的代码。

app.directive('browseContent', function() {

return {

restrict: 'E',

templateUrl: template_url + '/templates/browse-content.html'

}

});

在这里我正在尝试此代码

app.directive('browseContent', function() {

screen_width = window.innerWidth;

if (screen_width < 768) {

load_tempalte = template_url + '/templates/browse-content-mobile.html';

} else if (screen_width >= 768) {

load_tempalte = template_url + '/templates/browse-content.html';

}

return {

restrict: 'E',

templateUrl: load_tempalte

}

});

此代码块正常工作,它根据那里的分辨率加载移动和桌面页面,但是当我调整页面大小时,它保持不变…

例如,如果我在最小化窗口(480px)中打开浏览器并将其最大化为1366px,则templateUrl与“ /templates/browse-

content-mobile.html’”相同,它必须为“ /templates/browse-content.html”

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值