What is the best way to move between components within the same parent class using UI router in Angular 6?

Explore the Angular UI-Router Visualizer

design.component.ts

import { Component, OnInit, ChangeDetectorRef, EventEmitter, Output, Input } from '@angular/core';
import { AppService } from '@app/shared/app.service';
import { Schema } from '@app/shared/model/app.modal';
import { LiveAnnouncer } from '@angular/cdk/a11y';
import { StateService } from '@uirouter/core';

@Component({
  selector: 'app-design-app',
  templateUrl: './design-app.component.html',
  styleUrls: ['./design-app.component.scss']
})
export class DesignAppComponent implements OnInit {
  schema: Schema=new Schema(); 
  fields: object[] = this.appService.fields;
  mobileQuery: MediaQueryList;
  isScrolled: boolean;
  
constructor(private appService: AppService, private $state: StateService) {
  }

  sideNavScrollControl() {
    window.onscroll = () => {
      if (document.body.scrollTop > 140 || document.documentElement.scrollTop > 140) {
        this.isScrolled = true;
      } else {
        this.isScrolled = false;
      }
    };
  }

  previewPublish(){
    this.$state.go('login');
  }

  ngOnInit() {
  }

}

design.component.html

<!-- Preview, workflow and more actions button starts -->
<div class="preview-workflow-btn">
    <button mat-raised-button type="button" class="more-actions-btn" [matMenuTriggerFor]="menu">More Actions<i class="fa fa-sort-down dropdown-icon"></i></button>
    <mat-menu #menu="matMenu">
      <button mat-menu-item>Basic Details</button>
      <button mat-menu-item>Settings</button>
      <button mat-menu-item>Acceptance</button>
    </mat-menu>
  <button mat-raised-button type="button" class="workflow-btn">Workflow</button>
  <button mat-raised-button type="button" class="preview-btn" (click)="previewPublish">Preview</button>
</div>
<!-- Preview, workflow and more actions button ends -->

<div class="draggable-block-section" fxFlex="100" fxLayout="column">

<!-- Left form fields panel starts -->
  <div class="left-panel" fxFlex="50">
    <app-draggable [config]="fields"></app-draggable>
  </div>
<!-- Left form fields panel ends -->

<!-- Right panel starts -->
  <div class="right-panel" fxFlex="50">
    <app-blocks [config]="schema"></app-blocks>
  </div>
<!-- Right panel ends -->

</div>

Question: How can I successfully redirect to the horizontal view in the 'Preview-Publish' section upon clicking the 'Preview button' in the HTML file above? Any assistance would be greatly appreciated as the current click functionality does not seem to work. The goal is for the 'horizontal' view to automatically display when navigating to 'publish-preview'.

Answer №1

When working with HTML, you can implement it as shown below:

<div class="row directional-row">
    <a routerLink="/landing-page" title="Back">
      <i class="zmdi zmdi-arrow-left back_nav"></i>Back</a>
  </div>

Answer №2

<button mat-raised-button type="button" uiSref="preview-publish">Preview</button>

By default, when we navigate to the "preview-publish" route, it will redirect to the "horizontal" route as outlined below:

states: [
    {
      parent: "app-builder",
      name: "preview-publish",
      redirectTo: "horizontal",
      url: "/preview-publish",
      component: PreviewPublishComponent
    },
    {
      parent: "preview-publish",
      name: "horizontal",
      url: "/horizontal",
      component: HorizontalComponent
    },
    {
      parent: "preview-publish",
      name: "vertical",
      url: "/vertical",
      component: VerticalComponent
    },

  ], 

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Both undefined and null are sometimes allowed as values in conditional types, even when they should not be

Do you think this code should trigger a compiler error? type Test<T extends number | string> = { v: T extends number ? true : false } const test: Test<1> = { v: undefined } Is there something I am overlooking? Appreciate your help! ...

Using NestJS to import and inject a TypeORM repository for database operations

This is really puzzling me! I'm working on a nestjs project that uses typeorm, and the structure looks like this: + src + dal + entities login.entity.ts password.entity.ts + repositories ...

Arranging Angular Array-like Objects

I am in possession of an item: { "200737212": { "style": { "make": { "id": 200001510, "name": "Jeep", "niceName": "jeep" }, "model": { "id": "Jeep_Cherokee", "name": "Cherokee", "nice ...

Seeking out a particular key within a JSON object and then finding a match based on the id within that key's array - how can it be

Recently, I've been exploring JavaScript and encountering challenges when trying to apply array methods on objects. For instance, I received a fetch response and my goal is to extract the 'entries' key and then utilize the native Array.find( ...

Issue with TypeORM findOne method causing unexpected output

I am encountering an issue with my User Entity's Email Column when using TypeORM's findOne function. Instead of returning null for a non-existent email, it is returning the first entry in the User Entity. This behavior does not align with the doc ...

Expanding and shrinking div elements in Angular with sliding effects on other divs

Hello, I am just starting with angular and angular animations, and I have encountered a problem. Here is the html code that I am working with: <div class="main"> <div class="left" *ngIf="showLeftSide" [@slideInOutLeft]></div> <di ...

Insert a new row into the table with a value that is taken from the input fields on the form

view image details I am working on a form that consists of 4 fields: Name, Last name, email, and role. There is also a button. When the button is clicked, the input from the above form should be added as a new row in a table below. ...

Angular: Execute a function once all BehaviorSubject subscriptions have been initialized

In order to facilitate the sharing of parameters across components in my Angular application, I have implemented a "global" service as shown below: import { Injectable } from '@angular/core'; import { BehaviorSubject } from 'rxjs/BehaviorSu ...

Set an enumerated data type as the key's value in an object structure

Here is an example of my custom Enum: export enum MyCustomEnum { Item1 = 'Item 1', Item2 = 'Item 2', Item3 = 'Item 3', Item4 = 'Item 4', Item5 = 'Item 5', } I am trying to define a type for the f ...

Looking to execute a service method within an authguard service?

I am a beginner with Angular and I am looking to invoke a service method within the authguard service. The specific service function that I need is as follows. Please note that I do not want to make any changes to this service function. loadOrganizations() ...

Can you tell me the appropriate type for handling file input events?

Using Vue, I have a simple file input with a change listener that triggers the function below <script setup lang="ts"> function handleSelectedFiles(event: Event) { const fileInputElement = event.target as HTMLInputElement; if (!fileInp ...

The onChange event does not work as expected for Select controls

I am facing an issue with my common useForm.tsx file when handling the onChange event for select controls. The error message I encounter is displayed below. Does anyone have any suggestions on how to resolve this? Error: Type '(e: ChangeEvent<HTM ...

How can I adhere to Angular 2's naming convention for Input and Output as suggested by the styleguide?

Working with inputs and outputs while following Angular 2's styleguide naming convention Initially, my directive was defined like this: ... inputs: [ 'onOutside' ] ... export class ClickOutsideDirective { @Output() onOutside: EventEmitter ...

Dropdown Pattern with React CTA Modal

While using MaterialUI's ButtonGroup for a dropdown menu, I encountered an issue trying to set up a series of CTAs that are easily interchangeable within it. The goal is to have all components reusable and the choices in the dropdown dynamic. const C ...

Dismiss the Angular Material menu using the controller

Hey there! I've come across a bit of an issue where I can't seem to figure out how to close an Angular Material menu from my controller. The button that opens the menu looks like this: <md-icon class="add-note__icon" [mdMenuTriggerFor]="pale ...

Access a static class property through an instance

New and Improved Question: As I develop a client-side application, I am structuring an event-handling system inspired by the Redux framework. I have defined different event types as subclasses of a custom Event class. Each subclass includes its own stat ...

Exploring JSON data in Angular 7 by leveraging services

I am working on a node server which is returning the following JSON data: { "ResponseStatus": { "ResponseCode": 0, "ResponseMessage": "Success." }, "Events": [ { "CodEspec": 65957, ...

Following the upgrade to version 6.3.3, an error appeared in the pipe() function stating TS2557: Expected 0 or more arguments, but received 1 or more

I need some assistance with rxjs 6.3.3 as I am encountering TS2557: Expected at least 0 arguments, but got 1 or more. let currentPath; const pipeArgs = path .map((subPath: string, index: number) => [ flatMap((href: string) => { con ...

An Angular application caught in an endless cycle of redirects

Currently, I am working on an Angular project that involves the following routing configuration: const routes: Routes = [ { path: '', component: LoginLayoutComponent, children: [ { path: '', redi ...

Angular 8: Issue with PatchValue in Conjunction with ChangeDetector and UpdateValue

I am puzzled by the fact that PatchValue does not seem to work properly with FormBuilder. While it shows data when retrieving the value, it fails to set it in the FormBuilder. Does anyone have an idea why this might be happening? I am utilizing UpdateValue ...