如何传递onNext()名为"Category1"的控件的表单输入值?更改表单时,将传递该值,但是当用户未更改该值时则不会.我需要永远传递的价值.我该怎么做呢?
<div class="app-form container-fluid">
<div class="row">
<div class="col-6">
<div class="button-left float-left">
<button (click)="onPrevious('tab-empinfo')">Previous</button>
</div>
</div>
<div class="col-6">
<div class="button-right float-right">
<button
(click)="onNext('tab-selection', {
form: 'category',
data: {category: formCategory.value['Category1']}})">
Next
</button>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<h4>Category</h4>
</div>
</div>
<div class="row">
<div class="col-12">
<form #formCategory="ngForm">
<div class="form-group" *ngFor="let input of categorySelection; let i = index">
<choice *ngIf="input.type == 'choice'" name="Category{{ i + 1 }}" ngModel
[multiple]="input.multiple" [question]="input.question" [answers]="input.answers"></choice>
</div>
</form>
</div>
</div>
</div>
<pre>
{{ formCategory.value | …Run Code Online (Sandbox Code Playgroud) 以下不会将数组输出到控制台。范围不正确???
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Broker } from './broker';
@Injectable()
export class BrokerSurveyService {
brokers: Broker[] = [];
constructor(private http: HttpClient) {
this.getBrokers().subscribe((brokers) => {
this.brokers = brokers;
});
console.log(this.brokers); # Does NOT output to console
}
getBrokers() {
return this.http.get<Broker[]>('http://www.example.com/brokers.json');
}
}
Run Code Online (Sandbox Code Playgroud)
这会将数组输出到控制台,因为它在分配后立即发送到控制台。是this范围不同?我很困惑为什么。
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Broker } from './broker';
@Injectable()
export class BrokerSurveyService …Run Code Online (Sandbox Code Playgroud) 当我将以下代码添加到 main.ts 时,CustomEvent 未正确添加到窗口对象。如果我使用 JavaScript 控制台添加 CustomEvent,它会这样做。顺便说一句,当我单击触发我的自定义事件的按钮(称为:“选择单击”)时会出现问题。
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
function CustomEvent ( event, params ) {
params = params || { bubbles: false, cancelable: false, detail: undefined };
var evt = document.createEvent( 'CustomEvent' );
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
return evt;
}
CustomEvent.prototype = (<any>window).Event.prototype;
(<any>window).CustomEvent = CustomEvent;
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err)); …Run Code Online (Sandbox Code Playgroud)