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
}

2 Answers 2

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
};
Sign up to request clarification or add additional context in comments.

2 Comments

No but this is a common file and function that is for all the modules which are not angular implementation.
@user2375298 Check if this post stackoverflow.com/questions/22447374/… helps
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>
...

Comments

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.