创建angular项目,测试了很多次,一直报错,最后在小伙伴帮助下解决,分享最终正确姿势
下载淘宝镜像
npm install -g cnpm --registry=https://registry.npm.taobao.org
用镜像直接下载angular-cli
cnpm install -g @angular/cli
设置为淘宝镜像下载依赖
ng set --global packageManager=cnpm
创建新项目 demo
ng new demo
进入项目
cd demo
启动项目
ng serve
删除文件
rd demo /s
清屏
cls
项目中引入jQuery
cnpm install jquery --save
cnpm install @types/jquery --save-dev
知识点
父组件AppComponent会告诉子组件HeroDetailComponent要显示哪个英雄, 告诉的方法是把它的selectedHero属性绑定到HeroDetailComponent的hero属性上。 这种绑定是这样的:
<hero-detail [hero]="selectedHero"></hero-detail>
在等号的左边,是方括号围绕的`hero`属性,这表示它是属性绑定表达式的*目标*
在hero-detail.component.ts修改`@angular/core`导入语句,使其包含符号`[Input]
import { Component, Input } from '@angular/core';
在export 里写入 表示hero属性可输入
export class HeroDeatilComponent{
@Input() hero : Hero;
}
@
//引用服务时
import {Injectable} from '@angular/core';
@Injectable()














网友评论