0

In my angular view page, I have an div id whose click event is written in other java script file . Like a common java script file which is not related to the angular application. How to trigger the click event. The function in common javascript file is never triggered .

<div id="click" ..../>
//below one never works
$("#click").click(){
// do something
}
user2375298
  • 1,001
  • 4
  • 15
  • 28

2 Answers2

1

You don't have to do that, just use ngClick directive of angularjs.

<div id="click" ng-click="myFunc()" />

In your javascript file:

$scope.myFunc() = function () {
    // Do something
};
kelsier
  • 4,050
  • 5
  • 34
  • 49
  • No but this is a common file and function that is for all the modules which are not angular implementation. – user2375298 Mar 20 '15 at 13:46
  • @user2375298 Check if this post http://stackoverflow.com/questions/22447374/how-to-trigger-ng-click-angularjs-programmatically helps – kelsier Mar 21 '15 at 04:19
0

You can make a new module and controller with the file that contains the functions, then create a dependency for this new module/controller.

Auxiliar.js

(function(){
var app = angular.module('auxiliar',[]);

app.controller('CtrlAuxiliar',function(){

    this.sayHello = function(){
        console.log("Hello!");
        alert("Hello!");
    };


    });
})();

app.js

(function() {

  var app = angular.module('test',['auxiliar']);
  ...
  ...

index.html

<script type="text/javascript" src="auxiliar.js"></script>
...
...
<div ng-controller="CtrlAuxiliar as ca" ng-click="ca.sayHello()">Say Hello</div>
...
Jose Pablo
  • 111
  • 4