gpt4 book ai didi

javascript - Angular 2 测试应用程序卡在加载中

转载 作者:太空狗 更新时间:2023-10-29 17:55:15 24 4
gpt4 key购买 nike

为 Angular 2 制作测试应用程序但由于某些原因我无法解决,我的应用程序卡在“正在加载...”

文件如下:

应用程序组件.ts:

import {Component} from '@angular/core';
import {LittleTourComponent} from './little-tour.component';

@Component({
selector: 'my-app',
template: `
<h1>Test</h1>
<little-tour></little-tour>
`,
directives: [LittleTourComponent]
})
export class AppComponent { }

little-tour.component.ts:

import {Component} from '@angular/core';

@Component ({
selector: 'little-tour',
template: `
<input #newHero (keyup.enter)='addHero(newHero.value)'
(blur)="addHero.(newHero.value); newHero.value = '' ">

<button (click) = addHero(newHero.value)>Add</button>

<ul><li *ngFor='let hero of heroes'>{{hero}}</li></ul>
`,
})

export class LittleTourComponent {
heroes = ['Windstorm', 'Bombasto', 'Magneta', 'Tornado'];
addHero (value: string) {
if (value) {
this.heroes.push(value);
}
}
}

index.html:

<html>
<head>
<title>Angular 2 QuickStart</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">

<!-- Polyfill(s) for older browsers -->
<script src="node_modules/core-js/client/shim.min.js"></script>

<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>

<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
</head>

<body>
<my-app>Loading...</my-app>
</body>
</html>

和 main.ts:

import {bootstrap}    from '@angular/platform-browser-dynamic';
import {AppComponent} from './app.component';

bootstrap(AppComponent);

当我启动 npm 时,终端没有产生任何错误,但我确定我一定在代码中遗漏了一些东西。由于我仍在努力了解 Angular 2 的基础知识,因此非常感谢您的帮助。谢谢!

最佳答案

现在可以用这个了:

    <input #newHero (keyup.enter)='addHero(newHero.value)'
(blur)="addHero" newHero.value = '' >

plunker

您可以像这样将输入框中的值添加到列表中:

<input  [(ngModel)] = "newHero">
<button (click) = addHero(newHero)>Add</button>
<ul><li *ngFor='let hero of heroes'>{{hero}}</li></ul>

关于javascript - Angular 2 测试应用程序卡在加载中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37913586/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com