AngularJS – window resize and angular get element height in controller
Example 1 : angular get element height in controller
In this Post We Will Explain About is AngularJS – window resize and angular get element height in controller With Example and Demo.Welcome on infinityknow.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to angular get element height in controllerExample
In this post we will show you Best way to implement angularjs watch element height window innerheight AngularJS, hear for AngularJS – How to get window height in angular jswith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.
Include External Libs
[php]
angular-1.0.0.js // https://code.angularjs.org/1.0.0/angular-1.0.0.js
[/php]
Step 1 : HTML Part
[php]
your Browser window.width: {{windowWidth}}
BIGGEST AND FASTEST Web Tutorials
We are Web Technology Experts and Team who provide you very Important information on Web Development information,Examples and Demo, Interview Questions and Answers, live project problem solution and their solution and online free tutorials – “infinityknow.com”.
You can download free 100% source code and Demo from below link.
http://infinityknow.com/
http://infinityknow.com/tutorial
[/php]
Step 2 : javascript Part
[php]
var liveApp = angular.module(‘liveApp’, []);
function resizeCtrl($scope) {
/* Logic here or some angular code goes here */
}
liveApp.directive(‘resize’, function ($window) {
return function (scope, element) {
var w = angular.element($window);
scope.getWindowDimensions = function () {
return {
‘h’: w.height(),
‘w’: w.width()
};
};
scope.$watch(scope.getWindowDimensions, function (customval, oldValue) {
scope.windowHeight = customval.h;
scope.windowWidth = customval.w;
scope.style = function () {
return {
‘height’: (customval.h – 100) + ‘px’,
‘width’: (customval.w – 100) + ‘px’
};
};
}, true);
w.bind(‘resize’, function () {
scope.$apply();
});
}
});
[/php]
Step 3 : CSS Part
[php]
div {
border:2px solid green;
}
[/php]
Example 2 : angularjs set element height in controller
HTML Part (index.html)
[php]
Hello infinityknow.com ! width: {{width}}, height: {{height}}
[/php]
index.js
[php]
angular.module(‘liveApp’, [])
.directive(‘myDirective’, function($timeout) {
return {
restrict: ‘A’,
link: function(scope, element) {
scope.height = element.prop(‘offsetHeight’);
scope.width = element.prop(‘offsetWidth’);
}
};
})
;
[/php]
You can download free 100% source code and Demo from below link.
I hope you have Got What is angularjs get window height and width examples And how it works.I would Like to have FeadBack From My Blog(infinityknow.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(infinityknow.com) Are Most Always Welcome.