0
我有一個Angular組件(即時使用v1.5.6),它偵聽設備方向,然後在用戶使用平板電腦並轉向肖像時顯示消息模式(對此的檢查工作正常)。我的模板是:當使用addEventListener觸發屬性時,角度組件不會重新呈現
<div ng-show="$crtl.isTablet" class="orientation-warning-message tablet-warning-message">
<p>We think you are accessing this app on a tablet - you must use the app in landscape mode to continue (turn on side)</p>
</div>
和我的組件:
angular
.module('myApp')
.component('checkDevice', {
templateUrl: 'directives/checkDevice/checkDevice.tpl.html',
controller: function() {
var self = this;
this.isTablet = false;
window.addEventListener("orientationchange", function() {
// do some checks here and if a tablet and on portrait mode then:
self.isTablet = true;
}, false);
}
});
但該消息沒有顯示,因爲從addEventListener
回調中設置isTablet
不會出現重新渲染的成分。如果我在addEventListener
回調之外設置了isTablet
到true
,那麼它起作用。我是否需要手動觸發組件重新渲染?
該作品謝謝! – Mark
很高興幫助你! –