我正在使用Angular 5,我使用angular-cli创建了一个服务
我想要做的是创建一个服务,读取Angular 5的本地json文件.
这就是我的......我有点卡住......
import { Injectable } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
@Injectable()
export class AppSettingsService {
constructor(private http: HttpClientModule) {
var obj;
this.getJSON().subscribe(data => obj=data, error => console.log(error));
}
public getJSON(): Observable<any> {
return this.http.get("./assets/mydata.json")
.map((res:any) => res.json())
.catch((error:any) => console.log(error));
}
}
Run Code Online (Sandbox Code Playgroud)
我怎么能完成这个?
我正在使用angular 5,我正在尝试检查组件的html模板中变量的值.
所以它看起来像这样:
<div *ngIf="item='somevalue'">
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
ht错误:模板解析错误:
Parser Error: Bindings cannot contain assignments at column 17 in...
Run Code Online (Sandbox Code Playgroud)
这不能在角度上完成吗?
I am using angular 5 and I want to create new instances of a component on demand.
This is the code I currently have:
app.component.ts:
import { Component } from '@angular/core';
import { MyComponent } from './mycomp/my.component';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
constructor() {}
addCmp() {
console.log('adding');
// Add an instance of MyComponent code goes here ?
}
}
Run Code Online (Sandbox Code Playgroud)
app.component.html
<button (click)="addCmp()" >Add New MyComponent below</button>
Run Code Online (Sandbox Code Playgroud)
MyComponent.html:
<div>I am MyComponent</div>
Run Code Online (Sandbox Code Playgroud)
How can I …
我试图尽可能少地使用jQuery,我想将一些jQuery代码翻译成纯JS.
我有这个:
$(".myDiv").css({"width": 500});
Run Code Online (Sandbox Code Playgroud)
什么是上面代码的纯JS等价物?
我一直在看Angular 5的GET POST等:
get() {
return this.httpClient.get<any>('https://api.github.com/users/seeschweiler');
}
Run Code Online (Sandbox Code Playgroud)
要么
http.get<ItemsResponse>('/api/items')
.subscribe(
// Successful responses call the first callback.
data => {...},
// Errors will call this callback instead:
err => {
console.log('Something went wrong!');
});
Run Code Online (Sandbox Code Playgroud)
我不认为通常会使用诺言。
是因为不是真的需要它还是其他原因?