我从 angular 5.2 迁移到 6.0。当我发出 ng serve 命令时,出现以下错误:
src/app/mappy/mappy.component.ts(1,36) 中的错误:错误 TS2305:模块 '"C:/NSE911/applicationDev/angular/alo/node_modules/@angular/core/core"' 没有导出成员'状态'。
我正在使用:打字稿:2.7.2,角度cli:6.0.1,节点:8.11.2,操作系统:win32 x 64,角度:6.0.0,rxjs-compat:“^6.1.0”,
我删除了 node_modules 目录并重新创建了它(npm install)。这没有用。
我会很感激任何想法(我是使用这种技术的新手)。谢谢你的帮助。
我正在尝试创建嵌套的 json 对象,我已经为其创建了 Interface.I 收到错误Type of property serservicesAndHeads are incompatible并说Property is missing。我的界面如下:
interface Head {
HeadNumber?: string;
HeadDescription?: string;
};
interface ServicesAndHead {
majorService?: string;
subMajorService?: string;
servicesAndHeads:Head[];
}
export interface MyTableItem {
demandNo?: string;
demandName?: string;
servicesAndHeads?:ServicesAndHead;
//servicesAndHeads?:ServicesAndHead[];
}
Run Code Online (Sandbox Code Playgroud)
我的 json 看起来像这样:
const dataItem: MyTableItem =
{
demandNo: 'Demand Number 2',
demandName: 'Animal Husbandary, Livestock, Fisheries and Veterinary Services',
servicesAndHeads: [
{
majorService: 'C-Economic Service',
subMajorService: '(a) Agriculture and Allied Activities',
majorHead: [
{ majorHeadNumber: …Run Code Online (Sandbox Code Playgroud) 嘿伙计们,这似乎是什么问题?我在视图中使用开关盒。但它似乎不起作用。
template: `
<div [ngSwitch]="color">
<div *ngSwitchCase"'red'">You picked red</div>
<div *ngSwitchCase"'green'">you picked green</div>
<div *ngSwitchCase"'blue'">You picked blue</div>
</div>
`,
styles: [`
`]
})
Run Code Online (Sandbox Code Playgroud)
这是组件文件。
export class TestComponent implements OnInit {
public color = "red";
constructor() { }
ngOnInit() {
}
}
Run Code Online (Sandbox Code Playgroud)
我遇到过这样的情况,即在嵌套了几层深的容器边缘有单选按钮,并带有自动溢出。Angular 材质单选按钮具有波纹效果,会被剪裁。我没有重新处理整个事情,而是打算使用 disableRipple 关闭涟漪。这适用于点击,但在组件之间切换时似乎不起作用,如本stackblitz所示,如下面的屏幕截图所示,我切换到选项 1 而不是单击顶部的选项 1。我尝试更新 css 以显示:none,但是当焦点改变时根本没有视觉提示。在我看来,涟漪效应应该叠加以避免剪切问题,但这不是它的工作原理。那么有没有办法同时关闭标签和点击呢?
我正在使用 angular 6 创建带有 promise 的 post 请求。在我的服务中,我创建了一个请求函数,如下所示:
sendRequest() {
let promise = new Promise((resolve, reject)=>{
this.http.post(this.url, this.params, {responseType: 'text'}).toPromise()
.then(res =>{
this.data = res;
this.router.navigateByUrl('1/success'); // I want to show res code on this page
resolve();
},
error => {
this.data = error;
this.router.navigateByUrl('1/fail');
reject(error);
}
)
return promise;
})}
Run Code Online (Sandbox Code Playgroud)
res 以 html 格式返回文本,如下所示:
<html>
<head>
some code
</head>
<body>
code i need
</body>
</html>
,这很好,但我想在成功/失败页面上使用该文本作为 html 代码。具体来说,body 标签中的所有内容。我怎样才能做到这一点?如果我使用类似的东西
<div [innerHTML]="res"></div>
Run Code Online (Sandbox Code Playgroud)
或者
{{res}}
Run Code Online (Sandbox Code Playgroud)
它只返回纯文本。
当我为我的项目运行 Karma "ng test" 时,出现以下错误,
失败:模板解析错误:“mat-card”不是已知元素
但是当我们运行“ng serve”时,应用程序在使用 mat-card 标签时运行良好。我们正在使用 angular 6. 请求指导。
我正在使用 mat-drawer 并且我想在关联的组件中收到通知,当打开和关闭 mat-drawer 以添加一些逻辑时;
html 具有以下结构:
<mat-drawer-container class="example-container" autosize>
<mat-drawer #drawer class="custom-sidenav" mode="side">
<div>
<button routerLink="/" routerLinkActive="active"
style="margin-top: 50px" mat-button class="small" (click)="showFiller = !showFiller" >
<mat-icon style="color: red">home</mat-icon>
<b style="margin-left: 20px">Home</b>
</button>
</div>
<div>
<button routerLink="/transactions" routerLinkActive="active" style="margin-top: 20px" mat-button class="small" (click)="showFiller = !showFiller" >
<mat-icon style="color:gray">trending_flat</mat-icon>
<b matBadge="{{totalTransactions}}" matBadgeColor="red" matBadgeOverlap="false" style="margin-left: 20px">Transactions</b>
</button>
</div>
<div *ngIf="isAdmin">
<button routerLink="/fetch-data" routerLinkActive="active" style="margin-top: 20px" mat-button class="small" (click)="showFiller = !showFiller" >
<mat-icon matBadge="{{totalCertificates}}" matBadgePosition="before" matBadgeColor="accent" style="color:gray">description</mat-icon>
<b style="margin-left: 20px">Certificates</b>
</button>
</div>
<div> …Run Code Online (Sandbox Code Playgroud) 我有一个 Angular 6 应用程序,其中一个组件用于在页面上显示一条消息。一些消息包含嵌入其中的超链接(在 HTML 标记中)。但是,当消息显示在页面上时,它们将以纯文本形式显示(不呈现超链接,而是向用户显示标记)。
您可以访问 Stackblitz @ https://stackblitz.com/edit/angular-jj5nms以获取我为解释该问题而创建的示例应用程序。
预期的消息显示:
点击这里。
实际消息显示:
点击<a href=' http://www.google.com '>此处</a>
我正在使用 ReactiveFormModule 创建编辑表单。我想在编辑表单中显示数据,如文本框、下拉菜单、单选框和复选框。我可以使用setValue方法成功设置文本框和下拉列表的值。但我无法使用相同的值设置 Radio 组的值。
打字稿
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators, AbstractControl, ValidationErrors, FormControlName } from '@angular/forms';
import { HttpClient } from '@angular/common/http';
import { Observable, EMPTY, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
@Component({
selector: 'app-add',
templateUrl: './add.component.html',
styleUrls: ['./add.component.css'],
})
export class AddComponent implements OnInit {
stateList : any;
cityList: any;
genderList: any;
hobbyList: any;
name: FormControl;
age: FormControl;
state : FormControl;
city: FormControl;
myform: FormGroup; …Run Code Online (Sandbox Code Playgroud) 我正在对使用其他两个组件的组件进行单元测试。单击按钮时创建其他组件
.html
<div id="homepage-top-div" class="homepage-component-css-grid-container"> ...
<button id="get-question-list-button" [routerLink]="questionListRouterLink" class="btn content-div__button--blue css-grid-item-button-div btn-sm">See Questions</button>
</div>
<div id="practice-component-top-div" class="css-grid-container-div common-styles-div--white"> <!-- 4 rows, 1 column-->
...
<button id="new-question-button" [routerLink]="newQuestionRouterLink" class="btn content-div__button--blue css-grid-item-button-div btn-sm">Create a Question</button>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
.ts
export class HomepageContentComponentComponent implements OnInit {
public questionListRouterLink="/practice-question-list";
public newQuestionRouterLink="/new-practice-question";
constructor() {
}
ngOnInit() {
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个,spec但运行时出现以下错误-Failed: Unexpected directive 'NewPracticeQuestionComponent' imported by the module 'DynamicTestModule'. Please add a @NgModule annotation.
规格是
import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing'; …Run Code Online (Sandbox Code Playgroud) angular6 ×10
angular ×7
typescript ×4
javascript ×3
angular5 ×2
radio-button ×2
angularjs ×1
interface ×1
json ×1