angular问题汇总

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即可,至此,问题就解决

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值