我有一个手写数组来填充我班上的表格,现在我从 ngOnInit 上的 JSON 中获取这个数组的内容,但它的结构不是我需要的。
所以我正在尝试编写一个函数,用我在 ngOnInit 上得到的这个新函数来填充表数组。
问题是,当我在我的 TS 类中的函数之外编写代码时,我收到此错误“函数实现丢失或未立即跟在声明之后”。
为什么会这样,可以做些什么来解决这个问题?
TS
export class MyComponent implements OnInit {
users: Object;
constructor(private tstService: MyComponentService) { this.source = new LocalDataSource(this.data) }
ngOnInit(): void {
this.tstService.getTstWithObservable()
.map(result => result.map(i => i.user.data))
.subscribe(
res => { this.users = res; }
);
}
console.log(this.users); // Here, just an example. Throws 'Function implementation is missing or not immediately following the declaration'
data = [
{
title: 'Monthly',
sdate: '01/04/1990',
edate: '30/09/1990',
},
];
source: LocalDataSource; …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个带有取消和发送按钮的组件以避免每个表单上的 c&p 但我找不到将函数作为参数传递给组件选择器的方法
HTML:
<btn-submit [cancelFunction]='test' [acceptFunction]='test'></btn-submit>
Run Code Online (Sandbox Code Playgroud)
TS家长:
test = () => console.log("this is a test");
Run Code Online (Sandbox Code Playgroud)
TS孩子:
import { Component, Input } from '@angular/core';
@Component({
selector: 'btn-submit',
styleUrls: ['./btn.component.scss'],
template: `
<button class="btn" click="cancelFunction()">
<fa name="times"></fa>
</button>
<button class="btn" click="acceptFunction()">
<fa name="check"></fa>
</button>
`
})
export class BtnSubmitComponent {
@Input() cancelFunction: any;
@Input() acceptFunction: any;
}
Run Code Online (Sandbox Code Playgroud) 将我的代码更新为 HttpClient 后,我无法让 filter() 处理响应。我不断收到“对象”类型上不存在属性“过滤器”:
TS :
liqOnChange(selection): void {
this.http.get(this.json_liq).subscribe(res => {
this.arr = res.filter(
res => res.id == selection.target.value);
});
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试停止以名称 app_ 开头的所有容器
我虽然这会起作用:docker stop $(docker ps -f name="app_*"),但它显示:
unknown shorthand flag: 'f' in -f
See 'docker stop --help'.
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?
我正在从 Http 转移到 HttpClient,但现在我无法使用 map() 对结果进行排序,因此出现了一些错误。
使用 HttpClient,我得到“对象”类型上不存在属性“排序”。
this.getConcept().subscribe(res => {
res.sort((f, n): number => {
if (f.code < n.code) return -1;
if (f.code > n.code) return 1;
return 0;
});
console.error(res);
this.arrConcept = res;
});
Run Code Online (Sandbox Code Playgroud)
使用 Http 我可以毫无问题地对其进行排序
this.getConcept().map(this.extractData).subscribe(res => {
res.sort((f, n): number => {
if (f.code < n.code) return -1;
if (f.code > n.code) return 1;
return 0;
});
console.error(res);
this.arrConcept = res;
});
Run Code Online (Sandbox Code Playgroud) angular ×4
httpclient ×2
typescript ×2
class ×1
components ×1
declaration ×1
docker ×1
function ×1
http ×1
input ×1
javascript ×1
selector ×1
sorting ×1