【Angular】 学习笔记(一 基础)

一 、组件

1. 组件的创建

1.1 自动创建

ng generate component <component-name>

//默认创建目录:

一个以该组件命名的文件夹

一个组件文件 <component-name>.component.ts

一个模板文件 <component-name>.component.html

一个 CSS 文件, <component-name>.component.css
// 可以默认不创建这个 ng generate component <component-name> --skip-tests
测试文件 <component-name>.component.spec.ts

1.2 手动创建

import {
    Component, OnInit } from '@angular/core';

@Component({
   
  // 指定组件的CSS选择器 出现在模板中时以此实例化该组件
  selector: 'app-hello-world',   
  // 定义组件的模板 也可以直接在这里写 template: '<h1>Hello World!</h1>',
  templateUrl: './hello-world.component.html',  
  // 声明组件的样式,也可以直接在这里写  styles: ['h1 { font-weight: normal; }']
  styleUrls: ['./hello-world.component.less']
})

export class HelloWorldComponent implements OnInit {
   

}

二 、基础

1. 数据绑定 { { }}

// 静态数据文本绑定 {
   {}}
public title:string="123";
<h1>{
   {
   title}}</h1>

// html 绑定 [innnerHTML]解析
this.h="<h2>这是H2标签</h2>";
<div [innnerHTML]="h"></div>

2. 属性绑定 [ ]

<div [id]="id" [title]="title">属性绑定</div>

3. 数组循环 *ngFor

public List:string[] =['11','22','33'];
<ul>
	<li *ngFor="let item fo List;let key =index">
		{
   {
   key}}----{
   {
   item}}
	</li>
</ul>

4. 条件循环 *ngIf

<li *ngFor="let item fo List;let key = index">
	<span *ngIf="key===1" class="red">{
   {
   key}}----{
   {
   item}}</span>
	<span *ngIf="key!==1">{
   {
   key}}----
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值