When require()
is used to lazy-load stuff, it is asynchronous. The returned value is irrelevant. What you need is something like:
getTemplate: function () {
var template;
require(['text!templates/login/loginbox-template.html'], function (t) {
template = t;
// signal the application that template is resolved; I suggest promises
});
}
Asynchronous means that the result of the execution is not available immediately. The comment signal the application...
is a placeholder for the code that will notify the other parts of your application that the result is actually available and they can continue processing. This is tedious if you were not expecting it, but it is how things are.
Take a look at the JS Promise API, implemented by many great libraries, from jQuery to the standalone Q library.