我在RC4上,我收到错误由于我的模板,没有指令"exportAs"设置为"ngForm":
<div class="form-group">
<label for="actionType">Action Type</label>
<select
ngControl="actionType"
===> #actionType="ngForm"
id="actionType"
class="form-control"
required>
<option value=""></option>
<option *ngFor="let actionType of actionTypes" value="{{ actionType.label }}">
{{ actionType.label }}
</option>
</select>
</div>
Run Code Online (Sandbox Code Playgroud)
boot.ts:
import {disableDeprecatedForms, provideForms} from '@angular/forms';
import {bootstrap} from '@angular/platform-browser-dynamic';
import {HTTP_PROVIDERS, Http} from '@angular/http';
import {provideRouter} from '@angular/router';
import {APP_ROUTER_PROVIDER} from './routes';
import {AppComponent} from './app.component';
bootstrap(AppComponent, [ disableDeprecatedForms(), provideForms(), APP_ROUTER_PROVIDER, HTTP_PROVIDERS]);
Run Code Online (Sandbox Code Playgroud)
///所以这是我的DropdownList:
<fieldset ngControlGroup="linkedProcess" >
<div ngControlGroup="Process" >
<label>Linked Process</label>
<div class="form-group">
<select
ngModel
name="label"
#label="ngModel"
id="label" …Run Code Online (Sandbox Code Playgroud) 我在Ngfor中迭代一个json对象时遇到了麻烦,有我的模板:
模板:
<h1>Hey</h1>
<div>{{ people| json}}</div>
<h1>***************************</h1>
<ul>
<li *ngFor="#person of people">
{{
person.label
}}
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
人是我正在尝试迭代的json对象,我有(人| json)的结果而没有得到列表,这里是截图:

并完成,这是json文件的一部分:
{
"actionList": {
"count": 35,
"list": [
{
"Action": {
"label": "A1",
"HTTPMethod": "POST",
"actionType": "indexation",
"status": "active",
"description": "Ajout d'une transcription dans le lac de données",
"resourcePattern": "transcriptions/",
"parameters": [
{
"Parameter": {
"label": "",
"description": "Flux JSON à indexer",
"identifier": "2",
"parameterType": "body",
"dataType": "json",
"requestType": "Action",
"processParameter": {
"label": "",
"description": "Flux JSON à indexer",
"identifier": "4", …Run Code Online (Sandbox Code Playgroud) 我正在尝试直接访问JSON对象属性并记录它,这是我的函数:
loadProcesses(filter?){
this._postService.getAllProcess(filter)
.subscribe(
res=> {
this.processListe = res;
// console.log(this.processListe.)
}
,null,
() =>{
console.log("get processes liste" + filter)
});
Run Code Online (Sandbox Code Playgroud)
所以this.processListe包含一个JSON对象,我的JSON格式是这样的:
{"Person": {
"id": "A256",
"name": "GET",
"status": "active",
"description": "hardworking, openminded",
...
Run Code Online (Sandbox Code Playgroud)
所以它将包含完全相同的东西,例如,如果我想简单地在控制台日志上打印标签我该怎么办?
当我在订阅中记录我的变量的值时,我有一个值但是在外面做它时我得到未定义的???:
this._postService.getConf("app/conf/conf.json")
.subscribe(res =>{
this.home = JSON.stringify(res);
console.log("value :" + this.home);
Run Code Online (Sandbox Code Playgroud)
我想用一定的值初始化我的home变量我在ngOnInit上做它但是当我试图把它弄到外面时它得到值undefined:
这是我的功能:
getConf(url) {
return this._http.get(url).
map(res => {return res.json()});
}
ngOnInit() {
this._postService.getConf("app/conf/conf.json")
.subscribe(res => {
this.home = JSON.stringify(res);
console.log("hahowaaaaaaaa" + this.home);
}
);
this._postService.getPosts(this.home)
.subscribe(result =>{
this.loading = false;
this.actionsG = result;
var count = JSON.stringify(result);
this.aCount = count.substring(count.indexOf(','),23);
},error=> console.error('Error: ' + error), ()=> console.log('finish! ActionsG'));
this._postService.getPosts(this.home ).subscribe(result => this.actionsV =
result, error=> console.error('Error: ' + error), ()=> console.log('finish! ActionsV ngOnInit' + this.page));
}
Run Code Online (Sandbox Code Playgroud)