【问题标题】:Connecting 2 controllers and have access to the first controllers propertie in the second controller连接 2 个控制器并可以访问第二个控制器中的第一个控制器属性
【发布时间】:2014-10-10 15:13:13
【问题描述】:

我对角镖有疑问。 1 个用于触发作用域的 html 文件和 2 个控制器类 index.html

... {{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 上设置的时间是什么时候?似乎不是在构造函数完成之前。我必须在哪里调用我的方法?

现在我有一个问题,我必须在 SubController 类的 getData 函数中发出异步请求。这个http请求需要user.name属性来构建域,但是当我在构造函数中启动它时用户是不活动的。我无法将身份验证设置为第二个控制器。必须有另一种选择才能使其正常工作。

我为 dart 的未来尝试了几件事,但没有让我为物业工作。

【问题讨论】:

    标签: dart angular-dart dart-async


    【解决方案1】:

    这曾经是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
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多