如何从子路由组件获取数据

时间:2018-01-19 11:29:07

标签: typescript angular5 angular-router

请问这个问题的正确方法是什么?

我有一个父路由,它有一个创建团队表单和加载各种过滤表的子路由(这些是多选表)

父组件:

    $request = new \GuzzleHttp\Psr7\Request('PUT', $call->callback_url,
        [
            'cache-control' => 'no-cache',
            'Authorization' => 'Basic ' . $hash,
            'content-type' => 'application/x-www-form-urlencoded',
            'paymentStatusId' => "$orderstatusID"
        ]);

    $promise = $this->guzzle->sendAsync($request)->then(
        function (\Psr\Http\Message\ResponseInterface $response) use ($call) {

            if ($response->getBody() == '1') {
                $call->shopware_response = $response->getBody();
                $call->status = 'success';
            } else {
                $call->status = 'to_renewal';
            }
            $call->save();
        }
    );

    $promise->wait();

其中一个子路由组件

@Component({
  templateUrl: './users.component.html',
  styleUrls: ['./users.component.scss']
})
export class UsersComponent implements OnInit {

  organization: Organization;

  constructor(private route: ActivatedRoute,
    private teamService: TeamService,
    private oauthService: OAuthService) { }

  ngOnInit() {
    this.route.parent.data.subscribe(data => {
      this.organization = data['organization'];
    });
  }

  onCreateTeam(data) {
    this.teamService.createTeam({
      name: data.name,
      organizationId: this.organization.id,
      userIds: [...]
    });
  }

}

每个子路由组件都是类似的,并且具有@Component({ templateUrl: './all-users.component.html', styleUrls: ['./all-users.component.scss'] }) export class AllUsersComponent implements OnInit { @ViewChild(DtNavbarComponent) navbar: DtNavbarComponent; teams: Team[]; selectedUsers: SystemUser[]; constructor() { } ngOnInit() { } } 属性,该属性将保存从多选表中选择的用户

现在,在父组件中,用户可以输入团队名称并选择一个或多个用户,然后当用户单击“创建”时,我希望能够将DTO提交到父组件中的服务器:

selectedUsers

所以我的问题是当用户点击创建时,我将如何从子路径组件访问onCreateTeam(data) { this.teamService.createTeam({ name: data.name, organizationId: this.organization.id, userIds: [...] // this needs to be the property `selectedUsers` from the child route component }); } 属性?

0 个答案:

没有答案