How can I run controller function from the outside JS?

116 views
Skip to first unread message

David Marko

unread,
Apr 25, 2012, 4:22:36 AM4/25/12
to ang...@googlegroups.com
How can I run the controller function from the outside JavaScript? Inside the conrtoller I have some update function, which is bound to button and its used manualy by user on demand.  But I would like also to run this function on page load ($(document).ready ....) . Is there a way how to call this function (or in general any controller function or property value) ?

function MyCtrl($scope{
    $scope.update function(){....}
} 

Thanks,
David

Peter Bacon Darwin

unread,
Apr 25, 2012, 6:24:31 AM4/25/12
to ang...@googlegroups.com
The controller "constructor" function is run when the controller is instantiated.  You can just call the method there:

function MyCtrl($scope{
    $scope.update function(){....};
    $scope.update();
} 


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/QAApVruLj7YJ.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.

Reply all
Reply to author
Forward
0 new messages