学的前端框架多了,可以靠经验入门了,看上节建的示例

官网资料

https://angular.io/guide/architecture-components

1、启动位置

Angular8入门-2 第一个页面

 

 

 2、AppComponent

Angular8入门-2 第一个页面

 

 

 html 和 less分别是页面和样式

3、app.component.html

清空中间内容如下

Angular8入门-2 第一个页面

 

 

 增加一个helloWorld

<div class="header">HelloWorld</div>

 

Angular8入门-2 第一个页面

 

 

 在less里增加如下内容

Angular8入门-2 第一个页面

 

 

 跟着改变颜色

Angular8入门-2 第一个页面

 

 

 4、换一种写法

修改 I:\angular\ngstudy\src\app\app.component.ts如下

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

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.less'],
})
export class AppComponent {
  title = 'ngstudy';
  info="hello world1";
}

html 内容如下

<div class="header">{{info}}</div>

<router-outlet></router-outlet>

运行正常

Angular8入门-2 第一个页面

 

 5、下面搞一个点击事件试试,修改html和component代码如下

<div class="header" (click)="test()">{{info}}</div>

<router-outlet></router-outlet>
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.less'],
  
})
export class AppComponent {
  title = 'ngstudy';
  info="hello world1";
  test() {
    this.info="hello world2";
  } 
}

点击helloworld1,

Angular8入门-2 第一个页面

 

 运行成功,注意(click)不要写成ng-click,感觉挺简单的。。

相关文章:

  • 2022-12-23
  • 2021-10-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2021-11-11
猜你喜欢
  • 2021-05-07
  • 2021-10-15
  • 2022-12-23
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案