最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Angular 7工作方式事件綁定

 更新時(shí)間:2023年12月08日 10:59:11   作者:無(wú)涯教程  
在本章中將討論事件綁定在Angular7中的工作方式,當(dāng)用戶以鍵盤(pán)移動(dòng),鼠標(biāo)單擊或鼠標(biāo)懸停的形式與應(yīng)用程序交互時(shí),它將生成一個(gè)事件,需要處理這些事件以執(zhí)行某種操作,考慮一個(gè)示例以更好地理解這一點(diǎn)

Angular 7工作方式事件綁定

當(dāng)用戶以鍵盤(pán)移動(dòng),鼠標(biāo)單擊或鼠標(biāo)懸停的形式與應(yīng)用程序交互時(shí),它將生成一個(gè)事件,需要處理這些事件以執(zhí)行某種操作,考慮一個(gè)示例以更好地理解這一點(diǎn)

app.component.html

<!--The content below is only a placeholder and can be replaced.-->
<div style="text-align:center">
   <h1>Welcome to {{title}}.</h1>
</div>
<div> Months :
   <select>
      <option *ngFor="let i of months">{{i}}</option>
   </select>
</div>
<br/>
<div>
   <span *ngIf="isavailable; then condition1 else condition2">
      Condition is valid.
   </span>
   <ng-template #condition1>Condition is valid</ng-template>
   <ng-template #condition2>Condition is invalid</ng-template>
</div>
<button (click)="myClickFunction($event)">
   Click Me
</button>

在 app.component.html 文件中,無(wú)涯教程定義了一個(gè)按鈕,并使用click事件為其添加了一個(gè)函數(shù)。

以下是定義按鈕并為其添加函數(shù)的語(yǔ)法。

(click)="myClickFunction($event)"

該函數(shù)在: app.component.ts 中定義

import { Component } from '@angular/core';
@Component({
   selector: 'app-root',
   templateUrl: './app.component.html',
   styleUrls: ['./app.component.css']
})
export class AppComponent {
   title='Angular 7';
   
   //declared array of months.
   months=["January", "February", "March", "April", "May","June", "July", 
      "August", "September", "October", "November", "December"];
   
   isavailable=true; //variable is set to true
   myClickFunction(event) {
      //just added console.log which will display the event details in browser on click of the button.
      alert("Button is clicked");
      console.log(event);
   }
}

單擊按鈕后,控件將轉(zhuǎn)到函數(shù) myClickFunction ,然后將出現(xiàn)一個(gè)對(duì)話框,其中顯示已單擊按鈕,如以下屏幕截圖所示-

按鈕的樣式

添加在add.component.css中-

button {
   background-color: #2B3BCF;
   border: none;
   color: white;
   padding: 10px 10px;
   text-align: center;
   text-decoration: none;
   display: inline-block;
   font-size: 20px;
}

change事件添加

將onchange事件添加到下拉列表中,以下代碼行將幫助您將change事件添加到下拉列表中

app.component.html

<!--The content below is only a placeholder and can be replaced.-->
<div style="text-align:center">
   <h1>Welcome to {{title}}.</h1>
</div>
<div> Months :
   <select (change)="changemonths($event)">
      <option *ngFor="let i of months">{{i}}</option>
   </select>
</div>
<br/>
<div>
   <span *ngIf="isavailable; then condition1 else condition2">
      Condition is valid.
   </span>
   <ng-template #condition1>Condition is valid</ng-template>
   <ng-template #condition2>Condition is invalid</ng-template>
</div>
<br/>
<button (click)="myClickFunction($event)">
   Click Me
</button>

app.component.ts 文件中聲明

該函數(shù)在 app.component.ts 文件中聲明

import { Component } from '@angular/core';
@Component({
   selector: 'app-root',
   templateUrl: './app.component.html',
   styleUrls: ['./app.component.css']
})
export class AppComponent {
   title='Angular 7';
   //declared array of months.
   months=["January", "Feburary", "March", "April", "May", "June", "July", 
      "August", "September", "October", "November", "December"];
   isavailable=true; //variable is set to true
   myClickFunction(event) {
      //just added console.log which will display the event 
      details in browser on click of the button.
      alert("Button is clicked");
      console.log(event);
   }
   changemonths(event) {
      console.log("Changed month from the Dropdown");
      console.log(event);
   }
}

從下拉列表中選擇月份,您會(huì)在控制臺(tái)中看到控制臺(tái)消息" Changed month from the Dropdown"以及事件。

當(dāng)下拉列表中的值更改時(shí),讓無(wú)涯教程在 app.component.ts 中添加警報(bào)消息,如下所示-

import { Component } from '@angular/core';
@Component({ 
   selector: 'app-root', 
   templateUrl: './app.component.html', 
   styleUrls: ['./app.component.css'] 
}) 
export class AppComponent { 
   title='Angular 7'; 
   //declared array of months. 
   months=["January", "February", "March", "April", "May", "June", "July", 
      "August", "September", "October", "November", "December"]; 
   isavailable=true; //variable is set to true 
   myClickFunction(event) { 
      //just added console.log which will display the event 
      details in browser on click of the button. 
      alert("Button is clicked"); console.log(event); 
   } 
   changemonths(event) { 
      alert("Changed month from the Dropdown");
   } 
}

更改下拉列表中的值時(shí),將出現(xiàn)一個(gè)對(duì)話框,并顯示以下消息:

"Changed month from the Dropdown"。

以上就是Angular 7工作方式事件綁定的詳細(xì)內(nèi)容,更多關(guān)于Angular7事件綁定的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • AngularJS使用angular.bootstrap完成模塊手動(dòng)加載的方法分析

    AngularJS使用angular.bootstrap完成模塊手動(dòng)加載的方法分析

    這篇文章主要介紹了AngularJS使用angular.bootstrap完成模塊手動(dòng)加載的方法,結(jié)合實(shí)例形式分析了angular.bootstrap函數(shù)手動(dòng)加載模塊的步驟與相關(guān)操作技巧,需要的朋友可以參考下
    2017-01-01
  • AngularJS中$http的交互問(wèn)題

    AngularJS中$http的交互問(wèn)題

    本篇文章主要介紹了AngularJS中$http的交互問(wèn)題 ,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-03-03
  • 基于angular中的重要指令詳解($eval,$parse和$compile)

    基于angular中的重要指令詳解($eval,$parse和$compile)

    下面小編就為大家?guī)?lái)一篇基于angular中的重要指令詳解($eval,$parse和$compile)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-10-10
  • angular 用攔截器統(tǒng)一處理http請(qǐng)求和響應(yīng)的方法

    angular 用攔截器統(tǒng)一處理http請(qǐng)求和響應(yīng)的方法

    下面小編就為大家?guī)?lái)一篇angular 用攔截器統(tǒng)一處理http請(qǐng)求和響應(yīng)的方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-06-06
  • angular2 NgModel模塊的具體使用方法

    angular2 NgModel模塊的具體使用方法

    這篇文章主要介紹了angular2 NgModel模塊的具體使用方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • AngularJS深入探討scope,繼承結(jié)構(gòu),事件系統(tǒng)和生命周期

    AngularJS深入探討scope,繼承結(jié)構(gòu),事件系統(tǒng)和生命周期

    這篇文章主要介紹了AngularJS的scope,繼承結(jié)構(gòu),事件系統(tǒng)和生命周期,較為詳細(xì)的分析了scope的作用域、層次結(jié)構(gòu)、繼承及生命周期相關(guān)概念與使用技巧,需要的朋友可以參考下
    2016-11-11
  • Angular.js中處理頁(yè)面閃爍的方法詳解

    Angular.js中處理頁(yè)面閃爍的方法詳解

    我們?cè)趹?yīng)用的頁(yè)面或者組件需要加載數(shù)據(jù)時(shí),瀏覽器和angular渲染頁(yè)面都需要消耗一定的時(shí)間。這里的間隔可能很小,甚至讓人感覺(jué)不到區(qū)別;但也可能很長(zhǎng),這樣會(huì)導(dǎo)致讓我們的用戶看到了沒(méi)有被渲染過(guò)的頁(yè)面。本文將介紹Angular.js中處理頁(yè)面閃爍的方法。
    2017-03-03
  • angular實(shí)現(xiàn)圖片懶加載實(shí)例代碼

    angular實(shí)現(xiàn)圖片懶加載實(shí)例代碼

    本篇文章主要介紹了angular實(shí)現(xiàn)圖片懶加載實(shí)例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-06-06
  • AngularJs實(shí)現(xiàn)分頁(yè)功能不帶省略號(hào)的代碼

    AngularJs實(shí)現(xiàn)分頁(yè)功能不帶省略號(hào)的代碼

    這篇文章主要介紹了AngularJs實(shí)現(xiàn)分頁(yè)功能不帶省略號(hào)的代碼的相關(guān)資料,非常不錯(cuò)具有參考借鑒價(jià)值,感興趣的朋友一起看看吧
    2016-05-05
  • 在AngularJS應(yīng)用中實(shí)現(xiàn)一些動(dòng)畫(huà)效果的代碼

    在AngularJS應(yīng)用中實(shí)現(xiàn)一些動(dòng)畫(huà)效果的代碼

    這篇文章主要介紹了在AngularJS應(yīng)用中實(shí)現(xiàn)一些動(dòng)畫(huà)效果的代碼,AngularJS是一款熱門的JavaScript庫(kù),需要的朋友可以參考下
    2015-06-06

最新評(píng)論

托克逊县| 喜德县| 金堂县| 兴海县| 定边县| 九龙县| 金门县| 额敏县| 九江市| 吉木乃县| 中江县| 宕昌县| 华亭县| 孝义市| 云龙县| 资中县| 中超| 广安市| 乳山市| 湘阴县| 安康市| 漳平市| 临清市| 清丰县| 封丘县| 遂平县| 玉林市| 正安县| 双流县| 江阴市| 勃利县| 车险| 太谷县| 二手房| 吉安县| 建平县| 武隆县| 巩留县| 铜山县| 清水县| 吉林省|