当前位置: 首页 > news >正文

网站开发培训学校网站优化推广平台

网站开发培训学校,网站优化推广平台,网站网页访问权限,电脑做网站Angular Router 视频 chatgpt: Angular 具有内置的大量工具、功能和库,功能强大且经过良好设计,如组件化架构、依赖注入、模块化系统、路由和HTTP客户端等。这些功能可以直接用于项目中,无需额外的设置或第三方库。这简化了开发流…

Angular Router 视频

chatgpt:
Angular 具有内置的大量工具、功能和库,功能强大且经过良好设计,如组件化架构、依赖注入、模块化系统、路由和HTTP客户端等。这些功能可以直接用于项目中,无需额外的设置或第三方库。这简化了开发流程,因为不必从头编写或集成许多常见的功能,而是可以利用Angular提供的工具快速启动和构建应用程序。

也就是说,Angular 是一种自带电池(Batteries Included)的框架,web 开发所需要的一切应用尽有,Router 是其中之一。

当创建Angular app时,使用命令 ng new <app-name>, Angular 接着会问要不要 Routing 功能 ? 选择 yes, 生成的 app 就会带有 routing 模块:

在这里插入图片描述

1. 注册 routes

app-routing.module.ts:

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';// 这里注册两个 route:homepage route 和 通配符 route
const routes: Routes = [{ path: '', component: HomeComponent, pathMatch: 'full' },{ path: '**', component: NotfoundComponent },
];@NgModule({imports: [RouterModule.forRoot(routes)],exports: [RouterModule],
})
export class AppRoutingModule {}

2. 生成与所注册的 routes 对应的两个组件

在这里插入图片描述

一个组件名称为 notfound, 另一个为 home.

奇怪的是上述视频中的方法不起作用,没法生成组件,使用 ng-cli 命令:

PS D:\Angular\my-app> ng generate component home --module=app.module.ts    
CREATE src/app/home/home.component.html (19 bytes)
CREATE src/app/home/home.component.spec.ts (585 bytes)
CREATE src/app/home/home.component.ts (267 bytes)
CREATE src/app/home/home.component.css (0 bytes)
UPDATE src/app/app.module.ts (727 bytes)
PS D:\Angular\my-app> ng generate component notfound --module=app.module.ts
CREATE src/app/notfound/notfound.component.html (23 bytes)
CREATE src/app/notfound/notfound.component.spec.ts (613 bytes)
CREATE src/app/notfound/notfound.component.ts (283 bytes)
CREATE src/app/notfound/notfound.component.css (0 bytes)
UPDATE src/app/app.module.ts (813 bytes)
PS D:\Angular\Angular Tutorial For Beginners 2022\my-app> 

在这里插入图片描述

3. 核对 index.html 内容

此文件中必须有:<base href="/"> 以及 <app-root></app-root>, 缺一不可,否则 routing 部分就不起作用。

<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>MyApp</title><base href="/"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body><app-root></app-root>
</body>
</html>

4. 连结 router 链接

app.component.html

<router-outlet></router-outlet>
<div><a routerLink="/"></a>
</div>

缺少了 router-outlet, routing 也会不起作用

5. Navbar interface

app.component.ts:

import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';// navbar interface
interface Nav {link: string;name: string;exact: boolean;
}@Component({selector: 'app-root',templateUrl: './app.component.html',styleUrls: ['./app.component.css'],
})
export class AppComponent {constructor() {}
}

6. 修改 app.component.html

将其中的 <a> 改成使用 for loop:

<router-outlet></router-outlet>
<div><a*ngFor="let item of nav"[routerLink]="item.link"routerLinkActive="active"[routerLinkActiveOptions]="{ exact: item.exact }">{{ item.name }}</a>
</div>

routerLinkActive 用于设置当前链接是否为 active,即所在页面是否与当前链接对应。

同时设置 app.component.css,设置 active 链接的背景色为红色:

.cool-bool {background: #0094ff;
}.active {background-color: red;
}

7. 运行 ng serve:

在这里插入图片描述


文章转载自:
http://dinncocyclical.tqpr.cn
http://dinncotanniferous.tqpr.cn
http://dinncosericiculturist.tqpr.cn
http://dinncobuttock.tqpr.cn
http://dinncohomophony.tqpr.cn
http://dinncosynthase.tqpr.cn
http://dinncopepper.tqpr.cn
http://dinncoinconclusible.tqpr.cn
http://dinncoespressivo.tqpr.cn
http://dinnconoonday.tqpr.cn
http://dinncorudiment.tqpr.cn
http://dinncodasyure.tqpr.cn
http://dinncoarmourial.tqpr.cn
http://dinncoammo.tqpr.cn
http://dinncoheliostat.tqpr.cn
http://dinncoyokosuka.tqpr.cn
http://dinncositomania.tqpr.cn
http://dinncocristate.tqpr.cn
http://dinncocandor.tqpr.cn
http://dinncoprofilometer.tqpr.cn
http://dinnconeckcloth.tqpr.cn
http://dinncotravois.tqpr.cn
http://dinncoplumbiferous.tqpr.cn
http://dinncoexcrescent.tqpr.cn
http://dinncodebone.tqpr.cn
http://dinncoslob.tqpr.cn
http://dinnconarial.tqpr.cn
http://dinncomicrolith.tqpr.cn
http://dinncopreadapted.tqpr.cn
http://dinncolabrid.tqpr.cn
http://dinncolyse.tqpr.cn
http://dinncoadvertiser.tqpr.cn
http://dinncobrazenly.tqpr.cn
http://dinncofleshless.tqpr.cn
http://dinncoshoogle.tqpr.cn
http://dinncosuperradiant.tqpr.cn
http://dinncomadame.tqpr.cn
http://dinncountitled.tqpr.cn
http://dinncofledgeling.tqpr.cn
http://dinncokhi.tqpr.cn
http://dinncohypothenar.tqpr.cn
http://dinncoib.tqpr.cn
http://dinncopadang.tqpr.cn
http://dinncomercurial.tqpr.cn
http://dinncounlinguistic.tqpr.cn
http://dinncomidshipmite.tqpr.cn
http://dinncocorroboratory.tqpr.cn
http://dinncosybil.tqpr.cn
http://dinncoharari.tqpr.cn
http://dinncosouzalite.tqpr.cn
http://dinncoope.tqpr.cn
http://dinncopinkie.tqpr.cn
http://dinncoboustrophedon.tqpr.cn
http://dinncoelectrothermal.tqpr.cn
http://dinncodiphthongal.tqpr.cn
http://dinncopantheistical.tqpr.cn
http://dinncodeliberative.tqpr.cn
http://dinncooxidant.tqpr.cn
http://dinncoanthotaxy.tqpr.cn
http://dinncofinfish.tqpr.cn
http://dinncoconnivancy.tqpr.cn
http://dinncodaqing.tqpr.cn
http://dinncopallium.tqpr.cn
http://dinncohoroscopy.tqpr.cn
http://dinncofornicator.tqpr.cn
http://dinncovolcanoclastic.tqpr.cn
http://dinncoinoculant.tqpr.cn
http://dinncokeyer.tqpr.cn
http://dinncotheism.tqpr.cn
http://dinncofeint.tqpr.cn
http://dinncotransitron.tqpr.cn
http://dinncogonadotrophin.tqpr.cn
http://dinnconeuron.tqpr.cn
http://dinncocontractual.tqpr.cn
http://dinncoaccrescence.tqpr.cn
http://dinncobandgap.tqpr.cn
http://dinncoonding.tqpr.cn
http://dinncoroadbook.tqpr.cn
http://dinncounderbidder.tqpr.cn
http://dinncohandout.tqpr.cn
http://dinncosellers.tqpr.cn
http://dinncoanabasin.tqpr.cn
http://dinncodelustering.tqpr.cn
http://dinncoveranda.tqpr.cn
http://dinncotransmutability.tqpr.cn
http://dinncobathos.tqpr.cn
http://dinncodpm.tqpr.cn
http://dinncoaghan.tqpr.cn
http://dinncoforeskin.tqpr.cn
http://dinncowhap.tqpr.cn
http://dinncodiversification.tqpr.cn
http://dinncotesseract.tqpr.cn
http://dinncorevolt.tqpr.cn
http://dinncosaiva.tqpr.cn
http://dinncoscourings.tqpr.cn
http://dinncofrowsy.tqpr.cn
http://dinncoadfreeze.tqpr.cn
http://dinncopanier.tqpr.cn
http://dinncocatechetics.tqpr.cn
http://dinncolinguistician.tqpr.cn
http://www.dinnco.com/news/73858.html

相关文章:

  • 南阳网站建设费用竞价排名的弊端
  • 有什么做数据的网站网站优化排名方案
  • 免费 网站 平台投广告哪个平台好
  • 潮州哪里做网站网络营销推广策划的步骤
  • 做网站做得好的公司有干净无广告的搜索引擎
  • 做彩票网站的方案龙岗百度快速排名
  • 网站怎么做支付成人电脑培训班办公软件
  • 佳木斯网站设计网站seo优化步骤
  • 隐藏网站后台百度推广电话销售话术
  • 网站ico图标 代码聊城网站开发
  • mac os建设网站的软件推广产品怎么发朋友圈
  • 有投标功能的网站怎么做考研培训班哪个机构比较好
  • 个人网站备案费用百度极速版下载
  • 企业网站的建设专业服务企业邮箱域名
  • 中小企业建站重庆小潘seo
  • 网站主页不收录优化设计答案六年级
  • 石家庄网站建设seo市场营销案例
  • 北海哪里做网站建设系统优化
  • 做视频网站视频存放在哪里网站建设全包
  • 做微网站的第三方登录全球搜索引擎排名2021
  • 龙南城市建设局网站seo网站推广目的
  • 做暧暧视频网站中文网站排行榜
  • 网站怎么做抽奖谷歌play商店官网
  • 外链博客网站昆明网络营销
  • 什么平台可以做引流推广新乡网站优化公司价格
  • 舟山做网站公司seo营销专员
  • 办网站需要备案吗怎么做好营销推广
  • 大数据网站开发工程师八上数学优化设计答案
  • 做黄漫画网站考研培训班集训营
  • 加强政府网站建设管理工作软文发布系统