命名路由器插座无法正常工作

时间:2018-05-02 18:46:50

标签: angular routing angular-ui-router router router-outlet

我无法让命名路由器插座在我的角度应用程序中工作。下面的模板有工作代码,然后下面是我试过的两个单独的东西被注释掉了。它们被完全加下划线并导致此错误:

Parser Error: Missing expected : at column 18 in [[{ outlets: { new-user: ['new-user'] } } ]] in @31:13

我需要使用命名路由器出口,以便我可以在模板中的同一级别获取路由项目,以便在它们上正确使用cssFlex或cssGrid。我感谢您提供的任何见解!如果你给一个downvote,请说明为什么我可以改进这个问题。感谢。

我已经在命名和嵌套路由器插座上阅读了无数资源,但发现this one最直接。

模板: C:\ Users \用户nvaughn \文件\ TFSHome \ GWConnect \ SRC \ Gwi.WebUI \ ClientApp \ SRC \应用\布局\用户管理\用户management.component.html

<div class="blade-dashboard">
  <div class="blade-container">
    begining
    <div class="blade" [@routerTransition]>
      <div class="blade-header">
        <h1>User Management</h1>
        <div class="window-functions">
          <i class="fa fa-window-minimize"></i>
          <a routerLink="/dashboard" [routerLinkActive]="['router-link-active']">
            <i class="fa fa-window-close"></i>
          </a>
        </div>
      </div>
      <ul>
        <li>
          <i class="fa fa-users"></i>&nbsp;
          <a [routerLink]="['new-user']">New User Request</a>
          <!-- <a [routerLink]="['new-user', {outlets: {new-user:['new-user'], new-user-input: ['new-user-input']}}]">New User Request</a> -->
          <!-- <a [routerLink]="[{ outlets: { new-user: ['new-user'] } } ]">New User Request</a> -->
        </li>
        <br>
        <li>
          <i class="fa fa-users"></i>&nbsp;
          <a [routerLink]="['process-user']">Approve/Deny User Requests</a>
        </li>
        <br>
        <li>
          <i class="fa fa-users"></i>
          <a [routerLink]="['pending-user']">&nbsp;Pending User Requests</a>
        </li>
      </ul>
    </div>
    middle
    <router-outlet name='new-user'></router-outlet>
    <router-outlet name='new-user-input'></router-outlet>
    end
  </div>
</div>

路由模块: C:\ Users \用户nvaughn \文件\ TFSHome \ GWConnect \ SRC \ Gwi.WebUI \ ClientApp \ SRC \应用\布局\用户管理\用户管理-routing.module.ts

 import { PendingUserComponent } from './pending-user/pending-user.component';
    import { ProcessUserComponent } from './process-user/process-user.component';
    import { NgModule } from '@angular/core';
    import { Routes, RouterModule, RouterOutlet } from '@angular/router';
    import { UserManagementComponent } from "./user-management.component";
    import { NewUserComponent } from './new-user/new-user.component';
    import { NewUserInputComponent } from './new-user/new-user-input/new-user-input.component';


    const routes: Routes = [
  {
    path: '',
    component: UserManagementComponent,
    children: [
      // { path: "", redirectTo: "new-user" },
      {
        path: 'new-user',
        component: NewUserComponent,
        outlet: 'new-user',
        children: [
          {
            path: 'new-user-input',
            component: NewUserInputComponent,
            // outlet: 'new-user-input',
          }
        ]
      },
      { path: 'process-user', component: ProcessUserComponent },
      { path: 'pending-user', component: PendingUserComponent }
    ]
  }

];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  declarations: [NewUserComponent, ProcessUserComponent, PendingUserComponent, NewUserInputComponent],
  exports: [RouterModule]
})
export class UserManagementRoutingModule {
}

不要认为这很重要,但无论如何都包括在内...... 零件: C:\ Users \用户nvaughn \文件\ TFSHome \ GWConnect \ SRC \ Gwi.WebUI \ ClientApp \ SRC \应用\布局\用户管理\用户management.component.ts

import { Component, OnInit, Inject } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { HttpClient } from '@angular/common/http';
import { DataStateChangeEventArgs, Sorts, DataSourceChangedEventArgs } from '@syncfusion/ej2-grids';

import { UserService } from './../../shared/Services/UserManagement/User.service';
import { FormsModule } from '@angular/forms';
import 'rxjs/add/operator/map';
import { routerTransition, slideToRight } from "../../router.animations";
import {
  GridComponent, ToolbarItems, FilterSettingsModel, EditSettingsModel, ContextMenuItem
} from '@syncfusion/ej2-ng-grids';
import { Dialog } from "@syncfusion/ej2-popups";
import { FieldSettingsModel } from "@syncfusion/ej2-lists";


import { Users } from '../../shared/models/users.model';


@Component({
  selector: 'app-user-management',
  templateUrl: './user-management.component.html',
  styleUrls: ['./user-management.component.css'],
  animations: [slideToRight()]

})
/** UserManagement component*/
export class UserManagementComponent implements OnInit {

  public data: Observable<DataStateChangeEventArgs>;
  public pageOptions: Object;
  public editSettings: Object;
  public toolbar: string[];
  public state: DataStateChangeEventArgs;
  public users: Users[];

  public filterSettings: FilterSettingsModel;
  public contextMenuItems: ContextMenuItem[];
  public grid: GridComponent;
  public errorMessage = "";
  restoreMax = true;

  /** UserManagement ctor */
  constructor(private _userService: UserService) {
    this.getUsersData();
    this.data = this._userService;
  }

  getUsersData(): void {
    this._userService.getAllUsers()
      .subscribe((response) => { this.users = response; },
        (error) => { this.errorMessage = error.Message; });
  }

  public dataStateChange(state: DataStateChangeEventArgs): void {
    this._userService.execute(state);                     // for binding the data.
  }

  public dataSourceChanged(state: DataSourceChangedEventArgs): void {
    if (state.action === 'add') {
      this._userService.addUser(state).subscribe(() => state.endEdit());
    } else if (state.action === 'edit') {
      this._userService.updateUser(state).subscribe(() => state.endEdit());
    } else if (state.requestType === 'delete') {
      this._userService.deleteUser(state).subscribe(() => state.endEdit());
    }
  }



  ngOnInit(): void {

    // document.querySelector('.new-user-input').scrollIntoView({
    //   behavior: 'smooth'
    // });

}

1 个答案:

答案 0 :(得分:1)

想象一下你写了javascript代码:

var routerLink = [{ outlets: { new-user: ['new-user'] } } ];

这会有用吗?我认为它不会。

因为我们可以看到您正在使用减法new - user

模板中的行为相同。

为了修复路线:

[routerLink]="[{ outlets: { new-user: ['new-user'] } } ]"
                            ^^^^^^^^

考虑使用

之类的引号
[routerLink]="[{ outlets: { 'new-user': ['new-user'] } } ]"
                            ^^^^^^^^^^