我正在使用Angular 6 httpClient并在服务中包含以下代码:
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'text/xml' })
};
@Injectable({
providedIn: 'root'
})
export class ApiService {
constructor(private http: HttpClient) { }
post() {
const postedData = { userid: 1, title: 'title here', body: 'body text' };
return this.http.post('this url here', postedData, httpOptions).subscribe(result => {
console.log(result);
}, error => console.log('There was an error: '));
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:我想发布一个xml文件,那么我该如何修改此代码呢?
我试图实现angular MatSelectionList并尝试使用API selectionChange监听选定的选项事件,但它没有触发任何事件.
https://stackblitz.com/edit/angular-eyjdfp?file=app%2Flist-selection-example.html
我做错了什么或者在释放角度6时有什么破坏?
使用:Angular 6.0.1版本
Chrome浏览器
当我尝试添加最新的bootstrap版本时,我遇到了问题
npm install bootstrap
Run Code Online (Sandbox Code Playgroud)
当我尝试运行时,我收到一条错误消息
ng serve --open
Run Code Online (Sandbox Code Playgroud)
我在angular.json中添加了bootstap
像这样
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"src/styles.css"
],
Run Code Online (Sandbox Code Playgroud)
并且错误消息是
ERROR in multi ../node_modules/bootstrap/dist/css/bootstrap.min.css ./src/styles.css
Module not found: Error: Can't resolve '...\node_modules\bootstrap\dist\css\bootstrap.min.css' in '...'
Run Code Online (Sandbox Code Playgroud)
为什么我收到错误消息?
我在导入角度为6的observable的"of"方法时遇到问题,即使安装了新的项目,所有更新的软件包,我仍然会收到错误.所以,我做了一个小项目
这是服务给予
import { Injectable } from '@angular/core';
import { TableRow } from './table-row';
import { Observable, of } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class TestTableService {
private testData : TableRow[] = [
{id:1, name:'pi', value:3.14},
{id:2, name:'euler', value:2.71},
{id:3, name:'Feigenbaum constant', value:2.50290},
{id:4, name:'Mills constant', value:1.30637},
{id:5, name:'one', value:1},
{id:6, name:'square root of 2', value:1.41421}
];
constructor() { }
public getData() : Observable<TableRow[]>
{
return Observable.of(this.testData);
}
}
Run Code Online (Sandbox Code Playgroud)
这是使用它的组件:
import { Component, OnInit } from '@angular/core';
import …Run Code Online (Sandbox Code Playgroud) 我有一个数据表,我正在尝试分配<a>一个参与者名称<td>,该名称将在单击新组件时将用户带入。
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef> Name </th>
<td mat-cell *matCellDef="let Participant"> <a routerlink="/participants/userId">{{Participant.name}}</a> </td>
</ng-container>
Run Code Online (Sandbox Code Playgroud)
它没有显示错误或其他任何内容,但是,它没有使<td>clickable可用,它完全忽略了routerLink,如果我将分配href给<a>它的话。
angular-ui-router angular-material angular-material2 angular6
我已经搜索了很多有关此错误的信息,没有什么有用的,这种角度的错误通常会告诉您缺少提供程序的对象是什么,但是这次给出的是StaticInjectorError(AppModule)[[ object Object ]],所以我无法不知道。
在我的应用程序中,我有单独的模块:
他们每个人都有一个路由模块。的确,我正在使用lazyloading在模块之间进行路由。帐户路由模块包含:
const routes: Routes = [
{
path: '',
component: AccountsComponent,
canActivate: [AuthGuardService],
resolve: {
data:{
AccountsResolver
}
}
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
providers: [
AccountsResolver
]
})
export class AccountsRoutingModule {
}
Run Code Online (Sandbox Code Playgroud)
当我访问accountscomponent时,出现以下错误:
ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[[object Object]]:
StaticInjectorError(Platform: core)[[object Object]]:
NullInjectorError: No provider for [object Object]!
Error: StaticInjectorError(AppModule)[[object Object]]:
StaticInjectorError(Platform: core)[[object Object]]:
NullInjectorError: No provider for [object Object]!
at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (vendor.js:53611)
at resolveToken (vendor.js:53850) …Run Code Online (Sandbox Code Playgroud) 我几乎没有问题,可以将Angular应用程序从4升级到6。只有这个令人讨厌的警告出现在控制台中:
WARNING in ./node_modules/sax/lib/sax.js
Module not found: Error: Can't resolve 'stream' in 'D:\user\app\node_modules\sax\lib'
Run Code Online (Sandbox Code Playgroud)
我已经尝试删除node_modules指令并执行,npm install但是错误仍然出现。香港专业教育学院也试图添加
"paths": {
"sax": [
"../node_modules/sax/lib/sax.js"
]
}
Run Code Online (Sandbox Code Playgroud)
进入我的tsconfig.json文件。没有任何帮助。此外,通过谷歌搜索我还没有找到一个有用的解决方案。有谁知道得更好吗?
应该提到的是Im确切使用的依赖项:
"dependencies": {
"@angular/common": "6.1.3",
"@angular/compiler": "6.1.3",
"@angular/core": "6.1.3",
"@angular/forms": "6.1.3",
"@angular/http": "6.1.3",
"@angular/platform-browser": "6.1.3",
"@angular/platform-browser-dynamic": "6.1.3",
"@angular/router": "6.1.3",
"ag-grid": "^15.0.0",
"ag-grid-angular": "^15.0.0",
"angular2-multiselect-dropdown": "^2.5.0",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"enhanced-resolve": "^3.3.0",
"ngx-bootstrap": "^2.0.1",
"ngx-cookie-service": "^1.0.10",
"rxjs": "6.2.2",
"tinymce": "^4.6.3",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@PB/tslint-rules": "^0.7.0",
"@angular-devkit/build-angular": "~0.7.0",
"@angular/cli": "^6.1.3", …Run Code Online (Sandbox Code Playgroud) 我可以使用Angular中的查询参数过滤掉数据吗?This.rows是一个数组.我只会显示this.rows,其查询参数为"待定".我将如何使用queryParams过滤掉这个.这是我下面的代码.
// this.rows is an array
this.activeRouter.queryParams
.filter(params => params.q)
.subscribe(params => {
console.log(params);
if(this.rows.status === params.q){
return this.rows;
}
});
Run Code Online (Sandbox Code Playgroud) 任何人this._getReactions$.next()都this.http.get(...)可以在出现错误时不工作的情况下提供帮助。我想保持可观察状态以接受下一个输入。
private _getReactions$: Subject<any> = new Subject();
constructor() {
this._getReactions$
.pipe(
switchMap(() => {
return this.http.get(...)
// http request
}),
catchError(error => {
console.log(error);
return empty();
})
)
.subscribe(data => {
console.log(data)
//results handling
});
}Run Code Online (Sandbox Code Playgroud)
onClick() {
this._getReactions$.next();
}Run Code Online (Sandbox Code Playgroud)
我在TypeScript Angular6中使用jQuery时出现以下错误,请帮我
jQuery('#assignsp').modal('show');
Run Code Online (Sandbox Code Playgroud)
遵循这些步骤
3个步骤:
安装jQuery。(如果已安装,请跳过)
npm install jquery --save jQuery的安装类型。
npm install @ types / jquery-保存
Import jQuery in app.module.ts.
import * as $ from 'jquery';
Run Code Online (Sandbox Code Playgroud)
它告诉我错误
错误TS2339:类型“”上不存在属性“模式”JQuery<HTMLElement>
错误TS2339:类型“ JQuery”上不存在属性“模式”。
angular6 ×10
angular ×8
rxjs6 ×2
typescript ×2
css ×1
javascript ×1
jquery ×1
migration ×1
node-modules ×1
rxjs ×1