Javascript 异步内部函数返回[ui路由器和htmlservice]后返回外部fn
我正在尝试在应用程序脚本中使用ui路由器和客户端js HtmlService。经过详尽的尝试,我陷入了简单的js问题Javascript 异步内部函数返回[ui路由器和htmlservice]后返回外部fn,javascript,angularjs,google-apps-script,angular-ui-router,Javascript,Angularjs,Google Apps Script,Angular Ui Router,我正在尝试在应用程序脚本中使用ui路由器和客户端js HtmlService。经过详尽的尝试,我陷入了简单的js问题 .state('state1', { url: base+'?page=state1_KB', views: { 'content':{ template: function(){
.state('state1', {
url: base+'?page=state1_KB',
views: {
'content':{
template:
function(){
google.script.run.withFailureHandler(notemp).withSuccessHandler(temp).include(obj);
function temp(view){
console.log(view); //This logs successfully.
return view; //This works too I suppose
}
return temp(view); //This doesn't work obviously
},
controller: 'state1Controller'
}
}
})
include(obj)
获取模板并将其返回给temp(view)
。我需要从temp(view)
返回值。但很明显,它不会归还任何东西
如何在google.script.run
调用temp(view)
后返回外部函数
对于纯JS爱好者来说,我想这与此非常相似:
function outer(){
var a = "b";
setTimeout(function(){console.log("this is Log"); a = 'c';}, 2000);
return a;
}
从ui路由器或角度来看,是否有更简单的方法可以实现我在这里尝试的目标?类似的方法应该可以实现
templateProvider:
function($q){
var deferred = $q.defer();
var temp = function(view){
console.log(view);
deferred.resolve(view);
}
google.script.run
.withFailureHandler(notemp)
.withSuccessHandler(temp)
.include(obj);
return deferred.promise;
},
controller: 'state1Controller'
}
在第二个示例中,您认为outer()返回的值是多少?对于我给出的js示例,它应该是“b”。