0

Hello is there someone who knows: How can I execute an AngularJs method from plain javascript. =) Thanks.!!

myApp.controller("someController",["$scope",function($scope){
  //Some code was here
  $scope.a = valueA;
  $scope.b = valueB
});

and a bit later in the code want to execute a function that when valid could execute an IF and if thats the case will execute my AngularJS controller or what ever.

function Clicked(){
if( was clicked correctly ){
    //execute my Controller and send some data to add to the DOM
}
AstroCB
  • 12,337
  • 20
  • 57
  • 73
Julian
  • 33
  • 7
  • If you want to execute some thing in a button click why going for angular controller, write a javascript method. – ssilas777 Aug 28 '14 at 13:41
  • why would you want to do that, whats the use case ? – coder Aug 28 '14 at 13:42
  • 1
    [Like this](http://stackoverflow.com/questions/13743058/how-to-access-the-angular-scope-variable-in-browsers-console). But **why**? – CodingIntrigue Aug 28 '14 at 13:43
  • Because what I want to do it's to connect a small game I have in Phaser Framework with some external Elements that I have made in AngularJS. Think about it like a TV just that the bottoms and controllers are in Phaser and the Screen it's the Angular part. So basically when something happens in the Phaser part I want to communicated to the Angular part. =) Well this is my idea Hope I am clear and helpful to others.!! – Julian Aug 28 '14 at 15:10
  • http://stackoverflow.com/a/25569492/3986800 This is the solution, I answer in another post in stack – Julian Aug 29 '14 at 13:43

1 Answers1

2

Well, I don't think that's what you really want. Have a look at https://docs.angularjs.org/api/ng/directive/ngClick . You want your HTML elements to trigger a function inside your controller.

Jochen van Wylick
  • 5,303
  • 4
  • 42
  • 64
  • Thanks. But NO. because what I want to execute it's NOT inside of the DOM, it's inside a CANVAS element from JavaScript. – Julian Aug 28 '14 at 15:07
  • OK, relax. So you could use @RGrahams response, or maybe build up your canvas from your AngularJS controller and then, since you're inside the controller, have more easy access to it. – Jochen van Wylick Aug 28 '14 at 15:18
  • hehehe. Sorry thanks.!! ^^ I knew I could do that but I wanted to know if there was anyway I could executed from the outside of Angular so I could leave my controller light and simple. =) By the way thanks Really.!! – Julian Aug 28 '14 at 15:24