2017-05-25 21 views
0

ウィンドウのサイズを変更するたびにangleディレクティブから要素の幅を更新するにはどうすればよいですか?サイズ変更後にngスタイルの幅を更新する

今すぐバインドは1回だけです。

DIRECTIVE

function calculateGameWidth() {  
    scope.responsiveGameWidth = Math.floor((window.innerWidth - 22)/Math.floor((window.innerWidth - 22)/232)) - 6; 
    return scope.responsiveGameWidth; 
} 

calculateGameWidth(); 

//On resize 
window.onresize = function() { 
    calculateGameWidth(); 
} 

HTML

<li ng-style="{width: responsiveGameWidth+'px'}"></li> 

は事前にお願いします。

+0

https://stackoverflow.com/questions/30561615/css-update-on-resize-withを機能することはできません-angularjsは重複していますか? – sweaver2112

+0

すでにありません! :) –

答えて

1

角度周期外の範囲更新を実行しています。

あなたは

function calculateGameWidth() {  
    scope.responsiveGameWidth = Math.floor((window.innerWidth - 22)/Math.floor((window.innerWidth - 22)/232)) - 6; 
    scope.$apply(); 
} 

でこれを修正し、あなたの変数を使用し、

<li ng-style="{width: responsiveGameWidth+'px'}"></li> 
+0

コンソールのエラー - > $ digestはすでに進行中です –

+0

編集を参照してください - あなたは関数を呼び出していますが、htmlでする必要はありません –

+0

クール、ありがとうSir :) –

関連する問題