AngularJS学习笔记

本次实验通过Getting Start来完成

详细的教程为AngularJs

<h2>Products</h2>

<div *ngFor="let product of products">
//这这里对products中的内容进行了循环,并且可以从每一次循环中调用product值

  <h3>
    <a [title]="product.name + ' details'">
      {{ product.name }}
    </a>
  </h3>

  <p *ngIf="product.description">
    Description: {{ product.description }}
  </p>

  <button (click)="share()">
    Share
  </button>

</div>

AngularJS的基本用法

  1. *ngFor

  2. *ngIf:可以通过“”完成数据if语句的编写,这里支持js的常用判断编写

  3. 插值 {{}}:可以直接调用的数据内容

  4. 属性绑定 []:属性即为ALT,鼠标悬停可以查看到的数据内容

  5. 事件绑定 ():可以对需要参与的事件进行编写

在AngularJs的语法中是存在子父类的定义的,对于组件,调用它的组件即为其父类。当我们再定义一个组件的时候,如:

//app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
import { ReactiveFormsModule } from '@angular/forms';

import { AppComponent } from './app.component';
import { TopBarComponent } from './top-bar/top-bar.component';
import { ProductListComponent } from './product-list/product-list.component';
import { ProductAlertsComponent } from './product-alerts/product-alerts.component';

可以看出来我们再最后又引入Product_Alert组件
对于该组件使用的product_list为其父组件。
此时的product——list我们可以看到product_Alert的存在,通过属性绑定我们可以将product的值传进去

<h2>Products</h2>

<div *ngFor="let product of products">

  <h3>
    <a [title]="product.name + ' details'">
      {{ product.name }}
    </a>
  </h3>

  <p *ngIf="product.description">
    Description: {{ product.description }}
  </p>

  <button (click)="share()">
    Share
  </button>

  <app-product-alerts
  [product]="product">
</app-product-alerts>

</div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值