1.app.module.ts 基本理解? 模块基本定义:
//引入核心模块
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
//引入其他的自定义模块
import { AppComponent } from './app.component';
import { HeaderComponent } from './components/header/header.component';
import { NewsComponent } from './components/news/news.component';
import { HomesComponent } from './components/homes/homes.component';
//把一个类标记为 NgModule,并提供配置元数据。 https://angular.cn/api/core/NgModule
//declarations 属于该模块的一组组件、指令和管道(统称可声明对象)。
//imports 这里列出的 NgModule 所导出的可声明对象可用在当前模块内的模板中。
//providers 在当前模块的注入器中可用的一组可注入对象。
//bootstrap
//
@NgModule({
declarations: [
AppComponent,
HeaderComponent,
NewsComponent,
HomesComponent
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
2.组件component基本语法解释。
//从外部导入其他接口使用
import { Component, OnInit } from '@angular/core';
//声明这是一个组件
// selector 组件名称
// templateUrl 视图地址
// 样式地址
//
@Component({
selector: 'app-news',
templateUrl: './news.component.html',
styleUrls: ['./news.component.css']
})
//导出组件模块,组件最终是需要被其他模块引入并使用的
export class NewsComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
//父组件定义的方法
run(){
alert('我是父组件的方法,被子组件执行了');
}
}
3 vs code 的terminal新建angular 项目出现about_Execution_Policies
问题描述:
PS E:\Java\MyGitHub\personalCode\angularCodes> ng new angular10 --skip-install
ng : 无法加载文件 C:\Users\hp\AppData\Roaming\npm\ng.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.
com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 1
+ ng new angular10 --skip-install
+ ~~
+ CategoryInfo : SecurityError: (:) [],PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
解决办法:
①以管理员身份运行:
Wins+X
,然后点击A
,即可打开power shell
,即管理员身份的命令窗口
②输入:set-ExecutionPolicy RemoteSigned
,然后输入A
即可,至此,问题就解决