javascript - 使用 Angular 6 进行分步导航

标签 javascript angular viewchild

我需要您的帮助,因为我创建了一个导航步骤,但我不知道如何使用它。我使用 viewchild 但它对我来说不成功。我还尝试创建一个带有索引++的函数。同一页面上显示三个组件。我不知道该怎么办。我尝试不同的事情但没有结果。但找不到我想要的东西。

观看下面的图片

步骤导航图像:
Step nav image

export class NavbarComponent implements OnInit {

  public currentPage = 0;
  public changePage(change: number): void {
    this.currentPage += change;
  }

  thenBlock: TemplateRef<DragAndDropComponent>|null = null;
  show: boolean = true;
 
  @ViewChild('state')
  primaryBlock: TemplateRef<GridStateComponent>|null = null;
  @ViewChild('synthese')
  secondaryBlock: TemplateRef<GridSyntheseComponent>|null = null;

  constructor(private router: Router, private location: Location) { }

  ngOnInit() {


  }


}
 <section class="main__container--step">
    <!-- Header & Switch -->
    <header class="mg--lg">
        <div class="flex flex--jcsb flex--aic">
            <h2 class="title title--sm title--grey title--uppercase">Configure Grid</h2>
            <form class="switchToggle flex flex--jcsb flex--aic">
                <label class="flex flex--aic" for="configure" #configure>
                    <input type="radio" name="switchtoggle" id="configure" value="configure">
                    <span><a routerLink="configure" routerLinkActive="active" ></a>Configure</span>
                </label>
                <label class="flex flex--aic" for="grid" #state>
                    <input type="radio" name="switchtoggle" id="grid" value="grid" checked="checked">
                    <span><a routerLink="state" routerLinkActive="active" ></a>Grid State</span>
                </label>
                <label class="flex flex--aic" for="synthesis" #synthese>
                    <input type="radio" name="switchtoggle" id="synthesis" value="synthesis">
                    <span><a routerLink="synthese" routerLinkActive="active" ></a>Synthesis</span>
                </label>
            </form>
            <button class="button__step" (click)="continue()" ><a href="#">Continue</a></button>
        </div>
    </header>
    <!-- End Header & Switch -->
    <!-- End Main Content -->
</section>

最佳答案

如果您需要执行这些步骤的实际路由,您可以使用 <router-outlet></router-outlet>在按钮下;

假设我们的 html 有点像这样:

<div>
  <button [routerLink]="['', 'step-1']">Step 1</button>
  <button [routerLink]="['', 'step-2']">Step 2</button>
  <button [routerLink]="['', 'step-3']">Step 1</button>
</div>
<router-outlet></router-outlet>

那么你的路由文件应该与此非常相似:

const routes: Routes = [
  {
    path: '',
    component: StepParentComponent,
    children: [
      { path: 'step-1', component: StepOneComponent },
      { path: 'step-2', component: StepTwoComponent },
      { path: 'step-3', component: StepThreeComponent },
    ]
 }
];

然后在模块(应用程序或其他模块,如果不是根模块 - 使用 .forChild(routes) )内的路由声明中使用它们:

RouterModule.forRoot(routes)

关于javascript - 使用 Angular 6 进行分步导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52295254/

相关文章:

javascript - 替换除 <strong>、</strong>、<b> 和 </b> 之外的所有 HTML 标记

javascript - 基于 meteor 中选择下拉框的过滤器集合

javascript - 旋转 1 圈后暂停 SVG 动画

Angular ViewChildren 不会立即看到 ngFor 中的所有 child

javascript - Angular 2,与谷歌地图事件一起使用的子组件丢失上下文

javascript - React + D3 强制布局 : new Links have undefined positions

javascript - 如何更改 .css 类属性 - 背景 : url ('' ) for each item javascript/typescript

javascript - 错误 : property 'subscribe' does not exist on type 'OperatorFunction<{}, {} |可观察<任意>>

javascript - Angular 点击事件识别是鼠标点击还是键盘回车键事件

angular - 为什么即使 *ngIf 设置为 true,@ViewChild 仍然未定义