我正在进行API调用并存储一堆用户配置文件,我希望能够为每个配置文件动态创建卡(Angular Material Design md-card).返回的配置文件数量可能不同,因此需要是动态的.
这是我的组件文件,它生成JSONP请求并将配置文件存储在profiles
变量中:
import {Component, Injectable, OnInit} from '@angular/core';
import {Jsonp} from '@angular/http';
@Component({
selector: 'app-staff',
templateUrl: './staff.component.html',
styleUrls: ['./staff.component.css']
})
@Injectable()
export class StaffComponent implements OnInit {
public searchField: string;
apiRoot = 'this/is/my/api/url';
public results: JSON;
public profiles;
constructor(private jsonp: Jsonp) {
}
ngOnInit() {
}
setSearchField(field: string){ // ignore this method
this.searchField = field;
console.log('Received field: ' + this.searchField);
}
search(term: string) {
const apiUrl = `${this.apiRoot}?search=${term}&rows=10&callback=JSONP_CALLBACK`;
return this.jsonp.request(apiUrl).map(results => { this.results = results.json(); …
Run Code Online (Sandbox Code Playgroud) 我有一个称为动物的功能减速器(切片减速器)。我想将这些减速器拆分为哺乳动物、鸟类、鱼类等。这部分很简单,因为我可以简单地使用ActionReducerMap
.
现在假设哺乳动物的减速器状态很大,我想将其拆分为几个较小的减速器,即猫的家庭、狗的家庭等。 ActionReducerMap 不返回减速器并且不可嵌套。我尝试在网上搜索解决方案或示例,但找不到。简而言之,我的问题是如何制作多级嵌套减速器。
export interface AnimalsState{
mammals: fromMammals.mammalsState;
birds: fromBirds.birdsState;
}
export const reducers: ActionReducerMap<AnimalsState> = {
mammals: fromMammals.reducer,
birds: fromBirds.reducer
};
Run Code Online (Sandbox Code Playgroud)
我想将哺乳动物减速器拆分为更小的减速器。
我在这里有一个 plunker - https://plnkr.co/edit/QFB5eNQlRlXe7myrPsIs?p=preview
我知道这是一个愚蠢的例子,但我只是想使用(单击)和@Output 来获取工作示例。
我有一个计数器组件,它有两个按钮,增加和减少一个数字,另一个按钮,我想使用它在父组件上输出当前数字。
我知道愚蠢的例子,但只是想要一些简单的东西来学习@Output
import {Component} from '@angular/core'
@Component({
selector: 'app',
templateUrl: './src/app.component.html'
})
export class AppComponent {
myCount: number = 5
newCount: number
constructor() {
}
countChanges(event) {
this.myCount = event;
}
handleEventClicked(data){
this.newCount = data
}
}
Run Code Online (Sandbox Code Playgroud)