问题描述
我有角度飞镖的问题.1 个 html 文件来触发作用域和 2 个控制器类index.html
i have a problem with angular dart. 1 html file to trigger scopes and 2 controller classesindex.html
...{{subCtrl.user.name}}...
... {{subCtrl.user.name}} ...
第一个控制器
@Controller(
selector: '[mainController]',
publishAs: 'mainCtrl'
)
class MainController{
User user = new User('testuser');
MainController();
}
第二个控制器
@Controller(
selector: '[subController]',
publishAs: 'subCtrl'
)
class SubController{
@NgOneWay('user')
User user;
// constructor
SubController(){
getData();
}
void getData(){
if(user != null){
// following code is not exececutet, because user is null
httpRequst(...);
}
}
}
用户在@NgOneWay 上设置的时间是什么时候?似乎不是在构造函数完成之前.我必须在哪里调用我的方法?
when is the time user is set over @NgOneWay? seems like not before the constructor is finished. where do i have to call my method?
现在我遇到了问题,我必须在 SubController 类的 getData 函数中发出异步请求.这个 http 请求需要即 user.name 属性来构建域,但是当我在构造函数中启动它时用户不活动.我无法将身份验证设置为第二个控制器.必须有另一种选择才能使其正常工作.
now i have the problem i have to make a asynch request in the getData function in the SubController class. this http request needs i.e the user.name propertie to build the domain, but user is not active when i start it in the constructor. i cant set the authentification to the second controller. there must be another option to get this working.
为了 dart 的未来,我尝试了几件事,但没有让我为一家物业工作.
i tried several things with dart's future, but did not get i working for a propertie.
推荐答案
这曾经是 AttachAware
接口.
class SubController implements AttachAware {
attach() {
getData();
// or new Future(() => getData()); // if the line above still doesn't work - to give Angular one additional cycle to finish
}
}
这篇关于连接 2 个控制器并可以访问第二个控制器中的第一个控制器属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!