Call external js file function in Angular js controller

后端 未结 5 1939
挽巷
挽巷 2021-02-18 20:42

I have the external js file which has more functions.

I need to call these functions from angular controller.

For example: external.js



        
5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-18 21:06

    EDIT: gave wrong answer, my bad. the following example works.

    your external file should like this:

    var doSomething = (function () {
      "use strict";
       return {
          test: (function () {
            return 'test';
          }()),
          test2: (function () {
            return console.log('test 2');
          })
       };
    }());
    

    and in your controller you call your scripts function:

    console.log(doSomething.test);
    

    or

    doSomething.test2();
    

    i learned something too, thanks ;)

提交回复
热议问题