How to access the global javascript function using angularJS $window object and assign/bind it to the ng-model/scope variable? Have a javascript method defined outside scope of angular, need to access that method and get the returned value and assign/set it to scope variable! LINK
2 Answers
First off, you shouldn't be declaring methods outside of Angular. Use a service. If you absolutely need to bind a global method to the scope:
$scope.myFunc = $window.myFunc;
You can see a working solution in This plunk
7 Comments
John Smith
Have implemented your logic but still am not able to bind the value to view; plnkr.co/edit/EaXbLDCvsRlMO0PXTfqM?p=preview
SomeKittens
@JohnSmith That's because you're trying to assign a function to a model.
John Smith
My Mistake! Updated the plnk : plnkr.co/edit/EaXbLDCvsRlMO0PXTfqM?p=preview
JoseM
You also did not use the $window object, and in order to use the $window object you need to add it as a dependency. See updated plunk
SomeKittens
@JoseM is correct, if you want to use array injection, you need to declare the
$window dependency twice. |