我的项目中有一个JSON文件,如下所示:
{"_id":707860,"name":"Hurzuf","country":"UA","coord":{"lon":34.283333,"lat":44.549999}}
{"_id":519188,"name":"Novinki","country":"RU","coord":{"lon":37.666668,"lat":55.683334}}
{"_id":1283378,"name":"Gorkh?","country":"NP","coord":{"lon":84.633331,"lat":28}}
Run Code Online (Sandbox Code Playgroud)
我不知道如何遍历每一行以将其放入数组中.我怎样才能做到这一点?
我正在使用 *ngFor 指令来填充一系列 div。我也在使用 css 的 bootstrap 库。
<div data-toggle="collapse" data-target="#toggleDemo"*ngFor="let pair of pairings">
<div data-target="#toggleDemo">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我将有许多这样的条目,我想使用 bootstrap 中的展开/折叠。为了让它起作用,每个 div 必须有一个唯一的 data-target 属性值。
我想使用我的“配对”对象中的一个属性,但每次尝试时,我都会收到错误消息。
在 Angular4 中可以做这样的事情吗?
<div data-target="#toggleDemo-"{{ pair.id }}>
Run Code Online (Sandbox Code Playgroud)
编辑:
我试过这种方法
<div data-toggle="collapse" data-target="#toggleDemo-{{ pair.id }}">
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
Template parse errors:
Can't bind to 'target' since it isn't a known property of 'div'. ("v class="row" *ngFor="let pair of pairings">
<div class="wall col-sm-2" data-toggle="collapse" [ERROR ->]data-target="#toggleDemo-{{ pair.buyer.phone }}">
<p>{{ pair.buyer.name.first }} {{ pair.buyer.na"): ng:///AppModule/PairingsComponent.html@4:52 ; Zone: <root> ; …Run Code Online (Sandbox Code Playgroud) 我正在使用 Angular 8 编写一个应用程序。
我决定使用带有BehaviorSubject 的 rxjs 存储来进行简单的状态管理。
基本上,我的代码是一个存储、加载和更新用户权限的服务。有时,此信息将在 HTTP 调用后来自服务器,有时此信息将来自本地存储。用户权限更改后,所有订阅者都会得到更新。
这是我的 StackBlitz:https://stackblitz.com/edit/rxjs-state-management-get-set 请单击“添加配置文件”按钮以查看其运行情况。
这是我设置了单元测试的 StackBlitz:https://stackblitz.com/edit/rxjs-state-management-get-set-xpptmr
我已经使用基本的订阅者和完成技术编写了一些单元测试,但我想更深入地挖掘。
我读到我们可以使用“marbles”来测试 Observable 随着时间的推移的价值:https://rxjs-dev.firebaseapp.com/guide/testing/internal-marble-tests
我想使用弹珠来测试代码中的“加载”功能。
服务存储的代码片段:
@Injectable({
providedIn: 'root'
})
export class PersonaService {
private readonly data: BehaviorSubject<IPersonaData>;
public readonly sharedData: Observable<IPersonaData>;
constructor() {
this.data = new BehaviorSubject<IPersonaData>(null);
this.sharedData = this.data.asObservable() as Observable<IPersonaData>;
}
public load(): void {
const storedPersonaData: IPersonaData = {
currentPersonaIndex: null,
personas: []
};
const storedCurrentIndex: string = localStorage.getItem(Constants.KEYS.defaultPersonaIndex) as string;
if (storedCurrentIndex != null) {
storedPersonaData.currentPersonaIndex …Run Code Online (Sandbox Code Playgroud) 我正在编写一个小应用程序来定位一些旧的浏览器,但我很乐意在Angular 4中编写它.它可能吗?我需要哪种polyfils?
我正在用 Angular 5 编写一个应用程序。
我正在使用离子刷新器来刷新页面,如果出现错误或成功返回,我想取消微调器,因此基本上是一个 finally 块。
我需要刷新以停止旋转并在任何结果(成功或错误)中返回到默认位置。
我怎样才能用我的代码实现这一点?这是我尝试过的,但出现错误:
html
<ion-content>
<ion-refresher slot="fixed" (ionRefresh)="refresh($event)"></ion-refresher>
<div *ngIf="data">
{{ data }}
</div>
</ion-content>
Run Code Online (Sandbox Code Playgroud)
成分
export class UserInfoComponent implements OnInit {
data: any;
constructor(private userInfoService: UserInfoService) {}
ngOnInit() {
this.userInfoService
.getEmployeeInfo()
.subscribe((response) => {
this.data = response;
});
}
refresh(event) {
this.userInfoService
.getEmployeeInfo()
//.pipe(
//.finally(() => event.complete())
//)
.subscribe((response) => {
this.data = response;
event.complete(); //this works but what if there was an error
})
//.finally(() => event.complete());
//Property 'finally' does not exist …Run Code Online (Sandbox Code Playgroud) 我需要逐行构建一个字符串数组.它就像wordwrap.
我会输入这样的文字:
var inputString = 'There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration';
Run Code Online (Sandbox Code Playgroud)
我需要数组中的每一行最多38个字符.我不想在中间分割任何单词,所以如果38个字符位于单词的中间,则返回最近的空格字符.
期望的输出:
var output = [
'There are many variations of passages',
'of Lorem Ipsum available, but the',
'majority have suffered alteration'
];
Run Code Online (Sandbox Code Playgroud)
输出不正确:
'There are many variations of passages '
'of Lorem Ipsum available, but the majo'
'rity have suffered alteration.'
Run Code Online (Sandbox Code Playgroud)
我试图用空格字符拆分输入文本,最后得到:
var splitInput = [
'There',
'are',
'many'
...
]
function conc(arguments){
if (arguments.length === 0)
return …Run Code Online (Sandbox Code Playgroud) angular ×4
javascript ×3
arrays ×1
attributes ×1
html ×1
json ×1
polyfills ×1
recursion ×1
refresh ×1
rxjs ×1
string ×1
subscribe ×1
tags ×1
unit-testing ×1