2016-11-14 7 views
0

ウィンドウの高さ全体から一定量を引いたリサイズ範囲のdivを作成しようとしています。私は次のエラーを取得するいくつかの理由ディレクティブ内のウィンドウの高さを取得する際の具体的な問題

ionic.bundle.js:26794 TypeError: w.height is not a function 
at scope.getWindowDimensions (app.js:283) 
at Scope.$digest (ionic.bundle.js:30230) 
at Scope.$apply (ionic.bundle.js:30503) 
at done (ionic.bundle.js:24824) 
at completeRequest (ionic.bundle.js:25022) 
at XMLHttpRequest.requestLoaded (ionic.bundle.js:24963) 

私はヘッダから私のionic.bundle.jsを削除する場合は、それが動作します。 (私は、ブラウザでこれを使用していますことに注意してください)

指令

.directive('resize', function ($window) { 
    return function (scope, element) { 
     var w = angular.element($window); 
     console.log(w); 
     scope.getWindowDimensions = function() { return { 'h': w.height(), 'w': w.width() }; }; 
     scope.$watch(scope.getWindowDimensions, function (newValue, oldValue) { 
      scope.windowHeight = newValue.h; 
      scope.windowWidth = newValue.w; 
      scope.style = function (amount) { return { 'height': (newValue.h - amount) + 'px', 'width': (newValue.w - amount) + 'px' }; }; 
      scope.height = function (amount) { return { 'height': (newValue.h - amount) + 'px' }; }; 
     }, true); 
     w.bind('resize', function() { scope.$apply(); }); 
    } 
}) 

TEMPLATE

<div id="pageContent" ng-style="height(75)" resize> 
Stuff here 
</div> 

CSS

#pageContent { 
    position: relative; 
    padding-bottom: 20px; 
    z-index: 2; 
    overflow: auto; 
} 

答えて

0

気づかなかった場合、jQLiteはこれらのjQueryメソッドを実装していません。あなたが好きな(推奨しない)場合や、生のウィンドウオブジェクトを使用できる場合は、anglejsでjQueryを使用できます。

windowオブジェクトにはこれらの機能がありません。これらの関数は、jQueryを使用しているときに見つけることができます。ただし、生のjavascriptには、しかありません。window.screen.heightwindow.screen.widthがあります。

これを計算する適切な方法が見つかる場合は、Get the size of the screen, current web page and browser windowです。

またはw.screen.heightw.screen.widthを使用して簡単に指定します。

0

私は間違っている場合は私を修正しますが、私はあなたのアプリで画面の寸法を取得したいのですか?

さて、あなたは$windowを注入し、this ionicforumスレッドを次のように

$window.screenは外観を持って使用して、あなたの目的を達成するために$windowを使用する方法を理解することができ、このためjQLiteを使用する必要はありません。この記事の内容は、http://www.gajotres.net/ionic-framework-get-page-height-width/を参照してください。

これが役に立ちます。

関連する問題