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

Angular 11 is indicating that the type 'File | null' cannot be assigned to the type 'File'

Hey there, I'm currently diving into Angular and I'm working on an Angular 11 project. My task involves uploading a CSV file, extracting the records on the client side, and saving them in a database through ASP.NET Web API. I followed a tutorial ...

Angular material mat-calendar multiyear range selection视图

Experiencing an issue with a mat-calendar multiyear view. By default, the dropdown multiyear table displays 3 years back and 20 years forward from the current year (2016, 2017....2030). Instead, I am looking to view 23 years back starting from today' ...

Is there a way to incorporate TypeScript type definitions into a JavaScript module without fully transitioning to TypeScript?

Although the title may be a bit confusing, it encapsulates my query in a succinct manner. So, here's what I'm aiming to achieve: I currently have an npm module written in JavaScript, not TypeScript. Some of the users of this module prefer using ...

Looking to develop a dynamic password verification form control?

I am in the process of developing a material password confirmation component that can be seamlessly integrated with Angular Reactive Forms. This will allow the same component to be utilized in both Registration and Password Reset forms. If you would like ...

Creating Typescript libraries with bidirectional peer dependencies: A complete guide

One of my libraries is responsible for handling requests, while the other takes care of logging. Both libraries need configuration input from the client, and they are always used together. The request library makes calls to the logging library in various ...

Transferring information from a chosen <mat-option> to a different component in Angular Material

I am currently facing an issue with two components in my Angular application. The first component includes an Angular Material mat-option to select an option from a dropdown menu, while the second component is supposed to display the selected data. I attem ...

Resolve the issue of text overflow in PrimeNG Turbo Table cells

When utilizing Primeng table and enabling the scrollable feature, the table is expected to display a scrollbar while ensuring that the text within the cells does not overflow. Unfortunately, this expected behavior is not occurring. To see an example of th ...

Lookup users either by their email or their unique primary key in the form of a UUID

Currently, I am utilizing typeorm along with typescript and the postgresql driver Within my controller, below is a snippet of code: const userRepository = getCustomRepository(UserRepositories); const query = { by_email: {where: {email: user_receiver} }, b ...

What is the method for utilizing Tuple elements as keys in a Mapped Type or template literal within typescript?

Is there a specific way to correctly type the following function in TypeScript? Assuming we have a function createMap() that requires: a prefix (e.g. foo) and a tuple of suffixes (e.g. ['a', 'b', 'c']) If we call createMap(& ...

Having trouble incorporating @types/pdfmake into an Angular project

I have been experimenting with integrating a JS library called pdfmake into an Angular application. I found some guidance on how to accomplish this at https://www.freecodecamp.org/news/how-to-use-javascript-libraries-in-angular-2-apps/, which involved usin ...

Develop a TypeScript class in a distinct file

I currently have ag-grid implemented in an Angular project with a CustomFilter. The problem is that the file containing the code for the CustomFilter function is becoming quite large and difficult to manage. I am now looking to move the CustomFilter to a s ...

How can I display a header from one page on a different page in Ionic?

Using Ionic 3 on my Home Page, I have the following code snippet. Whenever the searchMore button is clicked, it leads to a new page. The objective is to display "Cook With What is in My Pantry" from the h5 tag on the new page. <ion-grid> <io ...

Error: Unable to connect to 'ngbTypeahead' as it is not recognized as a valid attribute of 'input' in the template

Having trouble with ngbTypeahead. The console is displaying the following error message: Error: Template parse errors: Can't bind to 'ngbTypeahead' since it isn't a known property of 'input'. (" <inpu ...

Having difficulty disassociating the radio button from the label

<div class="questions" style="font-size:13pt;margin-left:20px;margin-bottom:10px;"> <p class="question" id="ques{{i+1}}" style="font-size:17pt;font-weight:normal">{{i+1+". "+a.question}}</p> <img *ngIf="isImage[i]" [src]="a.image" ...

Storing the typeof result in a variable no longer aids TypeScript in type inference

Looking at the code snippet below: export const func = (foo?: number) => { const isNumber = typeof foo === 'number'; return isNumber ? Math.max(foo, 0) : 0; }; A problem arises when TypeScript complains that you cannot apply undefined to ...

Refreshing/reloading Angular 9 SSR pages

Encountering an issue with Angular and SSR. Running angular 9, everything runs smoothly except when I refresh the page (F5), it first displays the login page before loading the current page. Previously built with angular 8, where this problem did not occur ...

Safari (mac) experiencing issues with loading material icons properly on initial attempt

Upon my initial visit to the website, I noticed that the font appeared distorted. https://i.sstatic.net/BtUxI.png However, when I right-clicked and chose "reload page", the fonts were displayed correctly. https://i.sstatic.net/3XUcA.png This issue seem ...

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 ...

TypeScript causing issues when multiple selectors are used

Currently, I have a function that allows me to search for HTML elements based on text content: function findElementsByText(text: string): HTMLElement[] { const selectors = 'button' // This conditional statement ensures that an empty text quer ...

What is the best way to send ServerSideProps to a different page in Next.js using TypeScript?

import type { NextPage } from 'next' import Head from 'next/head' import Feed from './components/Feed'; import News from './components/News'; import Link from 'next/link'; import axios from 'axios&apo ...