I looked at this thread on the Angular way of getting an elements height, but as an angular newbie, I need a little help converting my own js to proper angular.
app.js
var AppModule = angular.module('App', ['ngAnimate', 'ngRoute']);
AppModule.config(function($routeProvider) {
$routeProvider
.when('/page:pageNumber', {
templateUrl: function ($routeParams) {
return '/app/..../assets/html/page' + $routeParams.pageNumber + '.php';
},
controller: "PageCtrl"
})
.otherwise({
redirectTo: "/page1"
});
});
controller.js
AppModule.controller("ViewCtrl", function($scope, $timeout) {
$scope.$on("$routeChangeSuccess", function(event, current, previous) {
$timeout(function() {
$scope.animationStyle = "slideRight";
height = document.getElementById('page' + $routeParams.pageNumber).offsetHeight;
document.getElementById('document').setAttribute("style","height:" + height + "px");
document.getElementById('document').style.height='"' + height + 'px"';
});
});
});
Firstly, I don't know how to call $routeParams
to get pagenumber
. I tried injecting $routeProvider
into the controller but this didn't help. It doesn't seem to be in $scope
either.
Secondly, I don't know if I should put the code for DOM manipulation in the controller. I just stuck it there to try and get it working (which it does for one page if I substitute height = document.getElementById('page' + $routeParams.pageNumber)
with height = document.getElementById('page2')