0

In my jQuery's document ready, I have something like

function resize() {
    textChatSection.css("width", $(window).width() - $('.user-list').width());
}

In the DOM, I have something like

<div id="users" ng-repeat="user in users" ng-controller="userController">
    <img src="test.png"/>
</div>

In another JS controllers file, I have a userController. The $scope.users array is empty on page load, but later on can have data, so the div is not being shown.

However when it's being shown, I need to run the resize() function. I tried making the function global (by assigning to a variable without the var infront) but it also fails. What's a good way to handle this?

Thanks

1 Answer 1

1

Try $viewContentLoaded. In your controller:

$scope.$watch('$viewContentLoaded', resize);

Eventually you probably want to do this in a directive. You want to avoid DOM manipulation in your controller.

Sign up to request clarification or add additional context in comments.

1 Comment

I've tried making the resize function global, by assigning it to a variable without the var keyword, but I still get the error that resize is undefined, most likely because it's inside document.ready.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.