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

Angular 7工作方式事件綁定

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

Angular 7工作方式事件綁定

當(dāng)用戶以鍵盤移動,鼠標(biāo)單擊或鼠標(biāo)懸停的形式與應(yīng)用程序交互時,它將生成一個事件,需要處理這些事件以執(zhí)行某種操作,考慮一個示例以更好地理解這一點(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 文件中,無涯教程定義了一個按鈕,并使用click事件為其添加了一個函數(shù)。

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

(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)一個對話框,其中顯示已單擊按鈕,如以下屏幕截圖所示-

按鈕的樣式

添加在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);
   }
}

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

當(dāng)下拉列表中的值更改時,讓無涯教程在 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); 
   } 
   changemonths(event) { 
      alert("Changed month from the Dropdown");
   } 
}

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

"Changed month from the Dropdown"。

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

相關(guān)文章

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

    AngularJS使用angular.bootstrap完成模塊手動加載的方法分析

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

    AngularJS中$http的交互問題

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

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

    下面小編就為大家?guī)硪黄赼ngular中的重要指令詳解($eval,$parse和$compile)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-10-10
  • angular 用攔截器統(tǒng)一處理http請求和響應(yīng)的方法

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

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

    angular2 NgModel模塊的具體使用方法

    這篇文章主要介紹了angular2 NgModel模塊的具體使用方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(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中處理頁面閃爍的方法詳解

    Angular.js中處理頁面閃爍的方法詳解

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

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

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

    AngularJs實現(xiàn)分頁功能不帶省略號的代碼

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

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

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

最新評論

丹棱县| 兰西县| 饶阳县| 海南省| 灯塔市| 四川省| 桃园市| 南乐县| 兴安县| 陇西县| 仁布县| 临武县| 东乌珠穆沁旗| 乌拉特前旗| 万盛区| 许昌县| 雷山县| 收藏| 科尔| 湖口县| 潍坊市| 宝山区| 朝阳区| 清镇市| 新津县| 宿州市| 和平区| 元阳县| 治县。| 杭州市| 银川市| 松江区| 南岸区| 英吉沙县| 乐都县| 原阳县| 金堂县| 如东县| 竹溪县| 桂平市| 榆中县|