私はOpenlayers 3マップを、ブラウザのサイズを変更するときに正しくサイズを変更する必要のある指示文の要素に入れました。Angular js set Openlayersはウィンドウ要素の寸法を動的にマップします
wmm.directive('tchOlMap', ['$window', function ($window) {
var hgt = ($window.innerHeight - 102);
var wdth = ($window.innerWidth - 400);
var MAP_DOM_ELEMENT_ID = 'tchMap';
return {
//restrict: 'E',
scope: false,
//replace: true,
template: '<div id="' + MAP_DOM_ELEMENT_ID + '" class="full-height" style="height: '+hgt+'px; width: '+wdth+'px; padding: 0px; margin: 0px; border:2px solid; border-color: #76AF75"></div>',
link: function postLink(scope, element, attrs) {
scope.isCollapsed = false;
var w = angular.element($window);
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;
console.log(newValue.w+' '+newValue.h);
hgt = newValue.h;
wdth = newValue.w;
scope.style = function() {
return {
'height': (newValue.h - 102) + 'px',
'width': (newValue.w - 400) + 'px'
};
};
}, true);
w.bind('resize', function() {
scope.$apply();
});
私はそれが更新さ寸法を返しているコンソールで見ることができますが、値が、私は要素に寸法を適用する方法のようにこだわっている要素に適用されていない - 誰も助けてくださいことはできますか?
感謝を@pedromarcするため、最終的な作業コードのおかげです。私はこれを試しましたが、今私はこの問題が発生しているhttp://stackoverflow.com/questions/31549494/angular-typeerror-name-replace-is-not-a-function-for-ng-style – Robert
scope.style shouldあなたが必要とするスタイルを含んでいるオブジェクトであるかどうかは、問題のスコープ内のスコープであるスコープが(おそらくエラーです)関数を保存していて、コントローラを更新してCSS定義でオブジェクトを保存するだけです。思う。 – pedromarce
ありがとう@pedromarc。私はリンク関数の開始時にスタイルオブジェクトを宣言し、$ watch関数でスタイルオブジェクトを渡しました。 – Robert