Lazy loading route remains unchanged even after passing id - html

Library is the parent component. In Home page, when I click on Library icon, I am led to Library page with URL localhost:4200/library, which is expected. In Library page, there's list of books. When I click on a book, I am led to book details of the selected book. However, the URL still remains localhost:4200/library which I would like to change to localhost:4200/library/book/selected-book-id.
Here's my attempt at it. The problem is the URL still remains localhost:4200/library, I would really appreciate some guidance.
library.routing.module.ts
const routes: Routes = [
{
path: '',
pathMatch: 'full',
component: LibraryComponent
},
{
path: '**',
redirectTo: ''
},
{
path: 'library/book/:selectedBookId',
component: BookComponent
}
];
#NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class LibraryRoutingModule {}
library-list.component.html
<div content class="content">
<scroll-viewer
class="library-list"
>
<mat-list data-custom-parent-group="LibraryList" data-custom-parentid="library-list">
<div class="loading" *ngIf="!ready">
<waiting-spinner
[size]="waitingSpinnerSize.Medium"
></waiting-spinner>
</div>
<ng-container *ngIf="ready">
<mat-list-item role="listitem" *ngFor="let book of library" style="margin-bottom: 2rem;height: auto;">
<button
mat-raised-button
class="menu-button"
[routerLink]="['/', 'library', '/', 'book', '/', book.id]"
routerLinkActive="active"
[ngClass]="{
unknown: true,
valid: false,
warning: false,
issue: false
}"
(click)="selectBook(book)"
[attr.data-custom-name]="book.id"
[attr.data-custom-name]="book.name"
[attr.data-custom-bhvr]="'Book'">
<div style="display: flex;place-content: space-between;align-items: center;line-height: 7rem;">
<div style="display: flex;">
<div class="book-subitem">
<div class="book-element">
<div class="book-name">Book: </div>
</div>
</div>
</div>
</div>
</button>
</mat-list-item>
<router-outlet></router-outlet>>
</ng-container>
</mat-list>
</scroll-viewer>
<mat-paginator #paginator class="paginator" [length]="resultsLength" [pageSize]="pageLength" [pageSizeOptions]="[5, 10, 25, 50, 100]" (page)="updatePage($event)"></mat-paginator>
</div>
</daui-layout-filter>

Related

Passing variable into [icon] for Font Awesome not working

I am using Font Awesome with Angular.
I want to loop through some data via *ngFor to create icons in a navigation bar. However, the [icon] is not accepting the values from the variable.
Component HTML
<div class="navbar-container container" [ngClass] = "expanded ? 'navbar-collapsed': ''">
<div class="navbar-logo-container">
<button class="logo" (click)="toggleCollapsed()">
A
</button>
<div class="logo-text" *ngIf="expanded">My Site</div>
</div>
<ul class="navbar-nav">
<li class="navbar-nav-item" *ngFor="let data of navData">
<a class="navbar-nav-link" [routerLink]="[data.routeLink]">
//works
<fa-icon [icon]="['fas','star']"></fa-icon>
//Error: Type 'string' is not assignable to type 'IconProp'.
<fa-icon [icon]="data.iconfull"></fa-icon>
// Type 'string' is not assignable to type 'IconProp'.
<fa-icon [icon]="[data.iconfirst,data.iconsecond]"></fa-icon>
<span class="navbar-link-text" *ngIf="expanded">{{data.label}}</span>
</a>
</li>
</ul>
</div>
Data
export const navbarData = [
{
routeLink: 'dashboard',
iconfirst: 'fas',
iconsecond: 'star',
iconfull: "['fas','star']",
label: 'Dashboard'
}
]
Cannot reproduce the third scenario.
From IconProp,
export type IconProp = IconName | [IconPrefix, IconName] | IconLookup;
Hence, for the second scenario,
Specify the navbarData type as:
import {
IconProp,
IconPrefix,
IconName,
} from '#fortawesome/fontawesome-svg-core';
navbarData: {
routeLink: string;
iconfirst: IconPrefix;
iconsecond: IconName;
iconfull: IconProp;
label: string;
}[] = [
{
routeLink: 'dashboard',
iconfirst: 'fas',
iconsecond: 'star',
iconfull: ['fas', 'star'],
label: 'Dashboard',
},
];
Sample Demo on StackBlitz

Some Elements in Vue components are not showing when called in a Single Vue File

I've completed designing my components with Vue 2, Vuetify and Vue cli - 4.5.15. I tried combining it in a Single Vue file but the components are not showing <v-icons> <v-textfield> and some other elements. I am not sure about why these kind of errors happen. I've attached the code of Component1 and Component2 and also the App.vue file's code.
Also in Control Panel I'm continuously getting error stating
Error in render: "TypeError: Cannot read properties of undefined (reading 'rtl')"
Component 1
<template>
<div class="post-wrap">
<div class="post-header">
<img src="https://www.finetoshine.com/wp-content/uploads/2020/04/Beautiful-Girl-Wallpapers-New-Photos-Images-Pictures.jpg" alt="" class="avator">
<div class="post-header-info">
<a class="location-link mintext"><v-icon small>mdi-map-marker</v-icon> BVB School, Thindal</a>
<span style="float:right;margin-right: 10px;" class="mintext">Jun 21</span>
<br>
<div style="margin-top:6px;margin-left:1px;display:inline-block;font-size:16px;">Steve Jobs</div>
·<span class="mintext"> Attended a Seminar</span>
<p>🔥 If you're tired of using outline styles for secondary buttons, a soft solid background based on the text color can be a great alternative.</p>
</div>
</div>
<div class="align-straight">
<img src="https://www.gizbot.com/images/2020-09/realme-7_159921061900.jpg" class="multi-img">
<img src="https://www.gizbot.com/images/2020-09/realme-7_159921061900.jpg" class="multi-img">
</div>
<span class="attached-link"> + 2 images</span><br>
<div class="align-straight">
<div class="document-wrap" style="display: inline-block;">
<v-icon dense>mdi-file-document</v-icon> document
</div>
<div class="document-wrap" style="display: inline-block;">
+ 2
</div>
</div>
<div class="align-straight like-bar">
<span><v-icon>mdi-thumb-up</v-icon></span>
<span style="float:right;margin-right: 20px;"><v-icon>mdi-bookmark</v-icon></span>
</div>
</div>
</template>
<script>
export default {
}
</script>
Component 2
<template>
<div class="newpost-wrap">
<v-form>
<div class="newpost-title">What's up</div>
<v-select label="Post Type" v-model="selectedPost" :items="postTypes" outlined></v-select>
<v-textarea v-model="newPost" :counter="280" label="New Post" hint="Share your Achievement !" required outlined></v-textarea>
<span class="update-link" #click="showAttach=!showAttach"><v-icon color="#3a7bd5">mdi-attachment</v-icon> Attach Files</span>
<div class="newpost-icons" v-if="showAttach==true">
<v-file-input small-chips multiple dense prepend-icon="mdi-wallpaper" accept="image/*" ></v-file-input>
<v-file-input small-chips multiple dense prepend-icon="mdi-file-document" accept="document/pdf, document/docx"></v-file-input>
</div>
<div class="update-btn">Post</div>
</v-form>
</div>
</template>
<script>
export default {
data: () => ({
showAttach: false,
newPost: '',
postType: null,
selectedPost: 'Usual',
postTypes: ['Seminar', 'Course', 'Project', 'Usual']
})
}
</script>
App.vue
<template>
<v-app >
<NewPostBar />
<UsualPost />
</v-app>
</template>
<script>
import NewPostBar from '/fac/faculty/src/components/NewPostBar.vue'
import UsualPost from '/fac/faculty/src/components/UsualPost.vue';
export default {
name: 'App',
components: {
NewPostBar,UsualPost
},
data: () => ({
})
};
</script>
Solved:
Hope this answers similar problems...
First I initialized a Vue project without including a router but then installed it as a plugin...then I got this error
So I initialized a Fresh project with a router installed with that...Now there's no error in the console, and the Project works just fine
But I am genuinely not aware of why this happened
Thanks to #tony19 for your response, So I was keep checking what was going wrong...

What I wrote to html doesn't register?

I am working on the Angular hotel project. There is a menu button on the main page and there are 2 options. Option 2 goes to the reservation detail page. The codes that I wrote in the html part of this component are not registered. I see the main article every time I run it (reservationdetail works!). How can I fix this.
.hotel-component-html
<button id="btnMenu" class="btn btn-warning" mat-button [matMenuTriggerFor]="menu">Reservations
Details</button>
<mat-menu #menu="matMenu">
<button mat-menu-item (click)="search2()">Price Search</button>
<button mat-menu-item (click)="navigate()">Reservations List</button>
</mat-menu>
.hotel-component-ts
navigate() {
this.router.navigate(["reservationdetail"]);
}
.reservationdetail-component-html
<p>Hello World!</p>
.app-routing-module-ts
export const routes: Routes = [
{ path: 'hotel', component: HotelComponent },
{ path: 'rezervazyon', component: RezervasyonComponent },
{ path: 'reservationdetail', component: ReservationdetailComponent },
{ path: "**", redirectTo: "hotel" }
];
.app-component-html
<div class='container-fluid'>
<div class='row'>
<div class='col-sm-3'>
</div>
<div class='col-sm-9 body-content'>
<router-outlet></router-outlet>
</div>
</div>
</div>
you need to change it to /reservationdetail as it is at same level as hotel, you need to navigate from root by using /
navigate() {
this.router.navigate(["/reservationdetail"]);
}
alternatively, you can just use a routerLink directive:
<button mat-menu-item routerLink="/reservationdetail">Reservations List</button>
If you keeps seeing the "reservation detail works!" even you have changed the content of the html file, this is a known bug of Angular ng serve. Just restart the dev server and it will be fine.

Use data in html from local json file - typescript, angular 7

I want to import a simple local json file in my angular 7 project and use the data in my HTML file. Just a simple example. I have attached a json file as data.json. I want to access the data from this json file in app.component.html in place of {{item}}
app.component.ts
#Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
#ViewChild('detailsPanel') details;
#ViewChild('displayDetails') displayDetails;
// Need to access this data from a json file
title = 'dragNdrop';
todo = [
'Get to work',
'Pick up groceries',
'Go home',
'Fall asleep'
];
done = [
'Get up',
'Brush teeth',
'Take a shower',
'Check e-mail',
'Walk dog'
];
elementDetails = "";
drop(event: CdkDragDrop<string[]>) {
if (event.previousContainer === event.container) {
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
} else {
transferArrayItem(event.previousContainer.data,
event.container.data,
event.previousIndex,
event.currentIndex);
}
}
showDetails(text){
this.elementDetails = text;
}
}
app.component.html
<div class="container-fluid" style="padding: 2%;">
<div class="row">
<div class="col-md-3">
<h2>Drag and Drop</h2>
</div>
</div>
<div class="row">
<div class="col-md-3" style="border-right: 1px solid black; height: 100%;">
<div cdkDropList #todoList="cdkDropList" [cdkDropListData]="todo" [cdkDropListConnectedTo]="[doneList]"
class="example-list" (cdkDropListDropped)="drop($event)">
<div class="example-box" *ngFor="let item of todo" cdkDrag>{{item}}</div>
</div>
</div>
<div class="col-md-6">
<div cdkDropList #doneList="cdkDropList" [cdkDropListData]="done" [cdkDropListConnectedTo]="[todoList]"
class="example-list" (cdkDropListDropped)="drop($event)">
<p #detailsPanel class="example-box" *ngFor="let item of done" (click)="showDetails(detailsPanel.innerText)" cdkDrag>{{item}}</p>
</div>
</div>
data.json
{
"list1": [
"A",
"B",
"C",
"D"
]
}
in
tsconfig.json
add into "compilerOptions":
"compilerOptions":
{
"resolveJsonModule": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
}
now you can import your data from your JSON in
yourComponentFile.ts
thereby:
import { yourObject } from './data/yourJSON.json'
and to use
dataImportedFromMyJson: any[] = yourObject;

The routes of Angular 6 do not work with the "Router" module, I think I have an error but I do not know what it is

I have the routes set and I have 2 Outlets, the primary and second called "Sesion", however, I established several routes for the "Sesion" Outlet, it only lets me go to the first, that is, when I press the "Ingresar" button ( you will see it later) it takes me effectively to the established route, and I change the component but when I try to change the contents of the Outlet with another button in the current component, it does not work anymore ... or to go back to visualize the previous component neither to go to another.
This is my routes ():
import { NgModule } from '#angular/core';
import { Routes, RouterModule } from '#angular/router';
import { AccionesComponent } from './acciones/acciones.component';
import { SesionComponent } from './sesion/sesion.component';
import { PostulacionComponent } from './postulacion/postulacion.component'
import { VotacionComponent } from './votacion/votacion.component';
const routes: Routes = [
{
path: "",
component: AccionesComponent
},
{
path: "votacion",
component: VotacionComponent
},
{
path: "",
component: SesionComponent,
outlet: "sesion"
},
{
path: "siguiente",
component: PostulacionComponent,
outlet: "sesion"
},
{
path: "votacion",
component: VotacionComponent,
outlet: "sesion"
}
];
#NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
My app.HTML (default component)
<div class="clearfix col contenedor">
<div class="column acciones">
<router-outlet></router-outlet>
</div>
<div class="column sesion">
<router-outlet name="sesion"></router-outlet>
</div>
</div>
My Sesion.component.html: (This button works "ingresar")
<div class="content1">
<div class="content2">
<div class="row">
<h1 class="tit"><b>Inicio de Sesión</b></h1>
</div>
<div class="row">
<input class="inputs" type="text" name="nombre" value="Usuario o código de empleado">
<br>
</div>
<div class="row">
<input class="inputs" type="text" name="pass" value="Contraseña">
<br><br>
</div>
<div class="row">
<input type="button" value="Ingresar" [routerLink]="[{ outlets: {sesion: ['siguiente'] } }]" routerLinkActive="active">
</div>
<div class="row">
<a class="tit2"><b>¿Olvidáste tu contraseña?</b></a>
</div>
</div>
</div>
My acciones.component.html (content of primary outlet)
<div class="tittle">#YoValoroOL</div>
<div class="text"><p>Apoya a tus colegas para que reciban el reconocimiento
que se merecen en el marco de los valores que nos definen como empresa.</p>
</div>
<div class= "tittle2">OLSoftware</div>
My postulation.component.html () (This button doesnt work "votar")
<div class="content1">
<div class="content2">
<h1 class="tit"><b>Postulaciones</b></h1>
<div class="label row">
Buscar por nombre:
</div>
<select class="inputs" name="nombrea">
<option value="volvo">Vanessa Velez Portera</option>
<option value="saab">Vanesa Velez</option>
<option value="fiat">Stiven Duran</option>
<option value="audi">Camila de la Espriella</option>
</select>
<br><br><br><br>
<div class="label row">
Buscar por rol:
</div>
<select class="inputs" name="passa">
<option value="volvo">Desarrollador Front-End</option>
<option value="saab">Vanesa Velez</option>
<option value="fiat">Stiven Duran</option>
<option value="audi">Camila de la Espriella</option>
</select>
<div class="content3">
<a [routerLink]="[{outlets:{sesion: ['votacion'] } }]"
routerLinkActive="active">Votar</a>
</div>
<div class="row">
<input type="button" value="Seleccionar">
</div>
</div>
</div>
My votacion.component.html: is just a default component
<p>
votacion works!
</p>
please Help me, i dont know the reason to not work
This is the error:
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'siguiente'
https://github.com/marco7247/APPDinam.git this is the code if someone could help me please.
EVEN IF I CHANGE THE ORDER TO THE ROUTES JUST WORK FIRST TIME WITH THE FIRST CHANGE.
The error "...Uncaught (in promise):..." is happening because the primary route cannot handle the 'siguiente' route.
To fix the route error you could add a primary catch all route:
{
path: '**',
component: AnotherComponent
}
or a primary named route:
{
path: 'siguiente',
component: AnotherComponent
}
Secondary routes aren't accessed via their name the same way as the primary routes.
The link to get to a secondary route would look like this http://localhost:4200/(sesion:siguiente).
accessing http://localhost:4200/siguiente, you will be hitting the primary route, and the secondary route will be resolved as '', that is why you are getting the SesionComponent contents in the secondary route-outlet.
You might want to visit the angular docs to learn more about it as well.
Update
also, the link needs to be fixed, this is the correct code to navigate the secondary route:
<a [routerLink]="[{ outlets: { sesion: ['votacion'] } }]"
routerLinkActive="active">Votar</a>
I found the problem... Angular presents errors if you don't use the primary outlet, i have created two new outlets and i wasn't using the primary one, so... thanks for trying to help me.