简体   繁体   中英

javascript function format which allow to be accessed from the same javascript file and HTML file

I need following javascript code add into a function. But this function should be able to call from both same JavaScript file and relative HTML code file.

Profile.query(function(result) { 
    SchedulesByInterviewer(result["userName"]); 
});

When I write the function in below format, it is ok to access it from HTML by calling vm.laodschedules(); but cannot be accessed from the JavaScript code.

vm.laodschedules = function(){
    Profile.query(function(result) { 
         SchedulesByInterviewer(result["userName"]);
    });
}

Then if I use below format it is ok to access the function from JavaScript code by calling laodschedules() but it cannot be accessed from HTML code.

function laodschedules() {
    Profile.query(function(result) { 
        SchedulesByInterviewer(result["userName"]);
    });
}

How can I manage to write this function enabling access from both JavaScript code and relevant HTML code?

Do this

 var laodschedules = function(){
        Profile.query(function(result) { 
             SchedulesByInterviewer(result["userName"]);
        })
    }

vm.laodschedules = laodschedules;

Now,

Call in controller (js) - laodschedules()

Call in view (html)- vm.laodschedules()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM