Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

angular - Hide and show the div on particular path

I have div and I need to show it on a particular(mentioned below) path. Thanks in advance.

Path

{ path: 'preview/:questionid', component: QuestionPreviewComponent, outlet: 'questions' }

http://localhost:3000/admin/questions/(questions:preview/5cb18f686560a2f98b43f8e0)

Routing Module

 imports: [RouterModule.forChild([
    { path: '', redirectTo: 'questions', pathMatch: 'full'},
    { path: 'questions', component: QuestionsComponent, children: [
      { path: '', component: QuestionListComponent, outlet: 'questions' },
      { path: 'bulk-upload', component: BulkUploadQuestionsComponent, outlet: 'questions' },
      { path: 'new', component: NewEditQuestionComponent, outlet: 'questions' },
      { path: 'edit/:id', component: NewEditQuestionComponent, outlet: 'questions' },
      { path: 'preview/:questionid', component: QuestionPreviewComponent, outlet: 'questions' }

    ]}
    ])],
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is couple of ways to do that one of them is as below...

I guess you have CSS code which shows your div suppose your class name is .displayDiv that class only hit when your the URL is something. http://localhost:3000/admin/questions/(questions:preview/5cb18f686560a2f98b43f8e0)

on component.ts file of QuestionPreviewComponent where you have to take variable like below...

pathName: any;

on

ngOnInit() {
this.pathName = location.pathname.split('/');
}

on HTML file of QuestionPreviewComponent

<div [ngClass]='pathName[2] === questions ? "displayDiv" : ""'>
------------------
------------------
Your code
-----------------
-----------------
</div>

You can leave else condition or add hide CSS if you prepare


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...