Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 每当我写“什么时候?”&引用;在{forms?.title}中,错误会消失,但标题不会显示在页面8上_Angular_Typescript_Angular8 - Fatal编程技术网

Angular 每当我写“什么时候?”&引用;在{forms?.title}中,错误会消失,但标题不会显示在页面8上

Angular 每当我写“什么时候?”&引用;在{forms?.title}中,错误会消失,但标题不会显示在页面8上,angular,typescript,angular8,Angular,Typescript,Angular8,这是我的.component.ts文件,我每次在html文件{{{forms?.contactNumber}中放入“?”时都遇到问题。错误会消失,但数据不会显示。我需要切换sidenav以显示数据,这很奇怪 import { Component, OnInit } from "@angular/core"; import { FormBuilder, FormGroup, Validators } from "@angular/forms"; import { ActivatedRoute, R

这是我的.component.ts文件,我每次在html文件{{{forms?.contactNumber}中放入“?”时都遇到问题。错误会消失,但数据不会显示。我需要切换sidenav以显示数据,这很奇怪

import { Component, OnInit } from "@angular/core";
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
import { ActivatedRoute, Router } from "@angular/router";
import { DealerapiService } from "../../services/dealerapi.service";
import { Observable } from "rxjs/internal/Observable";

@Component({
    selector: "kt-edit-contact",
    templateUrl: "./edit-contact.component.html",
    styleUrls: ["./edit-contact.component.scss"]
})
export class EditContactComponent implements OnInit {
    submitted = false;
    forms: Observable<any>;
    profileForm: FormGroup;
    constructor(
        private formBuilder: FormBuilder,
        private route: ActivatedRoute,
        private dealerApiService: DealerapiService,
        private router: Router
    ) {}

    ngOnInit() {
        this.viewData();
        this.profileForm = this.formBuilder.group({
            contactNumber: ["", Validators.required],
            address: ["", Validators.required]
        });
    }
    viewData() {
        this.dealerApiService.getUser().subscribe(
            (res: any) => {
                this.forms = res.data;
                console.log(res);
            },
            err => {
                console.log(err);
            }
        );
    }

    onSubmit() {
        this.submitted = true;
        if (this.profileForm.invalid) {
            return;
        } else {
        }
    }
}
从“@angular/core”导入{Component,OnInit};
从“@angular/forms”导入{FormBuilder、FormGroup、Validators};
从“@angular/Router”导入{ActivatedRoute,Router}”;
从“../../services/dealerapi.service”导入{DealerapiService}”;
从“rxjs/internal/Observable”导入{Observable};
@组成部分({
选择器:“kt编辑联系人”,
templateUrl:“./edit contact.component.html”,
样式URL:[“/编辑contact.component.scss”]
})
导出类EditContactComponent实现OnInit{
提交=错误;
形态:可见;
profileForm:FormGroup;
建造师(
私有formBuilder:formBuilder,
专用路由:激活的路由,
私有dealerApiService:dealerApiService,
专用路由器
) {}
恩戈尼尼特(){
这是.viewData();
this.profileForm=this.formBuilder.group({
联系人号码:[“”,验证器。必需],
地址:[“”,验证器。必需]
});
}
viewData(){
此.dealerApiService.getUser()已订阅(
(res:any)=>{
this.forms=res.data;
控制台日志(res);
},
错误=>{
控制台日志(err);
}
);
}
onSubmit(){
this.submitted=true;
if(this.profileForm.invalid){
返回;
}否则{
}
}
}
试着这样做:

用空对象声明
表单

forms: Observable<any> = {}
试着这样做:

用空对象声明
表单

forms: Observable<any> = {}

你必须把可观察的赋值给这样的形式

  viewData() {
           this.forms= this.dealerApiService.getUser();
        }
在html中,将其与异步管道
{{forms | async}}
别忘了在destroy中取消订阅

或者你可以把它当作不可观察的对象
形式:any

在html中,将是
{{forms?.contactNumber}

您必须将observatable分配给这样的表单

  viewData() {
           this.forms= this.dealerApiService.getUser();
        }
在html中,将其与异步管道
{{forms | async}}
别忘了在destroy中取消订阅

或者你可以把它当作不可观察的对象
形式:any

在html中是
{{forms?.contactNumber}

我不认为您的表单属性是一个观察对象,它只是一个我认为经销商api将返回的对象,因此在组件模板渲染时表单是未定义的,并且可以从未定义的对象(如此表单)访问任何子值。联系人号码将引发如下错误

无法读取未定义的属性“contactNumber”


您可以通过以下解决方案之一解决此问题我不认为您的表单属性是一个观察对象,它只是一个我认为经销商api将返回的对象,因此在组件模板渲染时表单是未定义的,并且从未定义的对象(如此表单)访问任何子值。联系人号码将抛出错误像

无法读取未定义的属性“contactNumber”


您可以通过以下解决方案之一解决此问题“表单”不是可观察的,只是一个对象,因此请定义表单:无论如何,您介意共享您的组件.html吗?“表单”不是可观察的,只是一个对象,所以定义表单:随便你介意共享你的组件.html吗?您好,数据仍然没有显示,但当我单击sidenav时,它显示向上,但当我没有添加问号时,数据显示出来。当我导航到其他页面数据时,我使用sidenav,但数据没有显示。请在stackbiltz和shareHello中创建它,数据仍然没有显示,但当我点击侧导航时,它会向上显示,但当我没有添加问号时,数据会显示。当我导航到其他页面数据时,我使用侧导航,但不显示。请在stackbiltz和Share中创建它。如果你使用异步管道,你不需要取消订阅。当我导航到其他页面数据时,我使用侧导航,你不需要如果使用异步管道,则取消订阅当我导航到其他页面数据时Im使用侧导航不显示当我导航到其他页面数据时Im使用侧导航不显示当我导航到其他页面数据时Im使用侧导航不显示