Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.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
类型“string[]”上不存在Angular 5属性“username”_Angular_Typescript - Fatal编程技术网

类型“string[]”上不存在Angular 5属性“username”

类型“string[]”上不存在Angular 5属性“username”,angular,typescript,Angular,Typescript,我正在尝试制作一个简单的编辑组件。从Javascript的角度来看,我看不出任何错误,但我认为我没有按照Angular希望的方式使用范围,所以我正在寻找一些指导。src\app\admin\customers\customer edit\customer edit.component中出错。html10,97::类型“string[]”上不存在属性“username” customer-edit.component.ts 我的Html代码是 customer-edit.component.htm

我正在尝试制作一个简单的编辑组件。从Javascript的角度来看,我看不出任何错误,但我认为我没有按照Angular希望的方式使用范围,所以我正在寻找一些指导。src\app\admin\customers\customer edit\customer edit.component中出错。html10,97::类型“string[]”上不存在属性“username”

customer-edit.component.ts

我的Html代码是 customer-edit.component.html

人们期望什么

我不知道是因为我的写作,还是因为造成我这个错误的配置。我根据官方文件编写了代码。我相信它能成功建造

到底发生了什么

当我运行npm run build时,完整的提示如下:

1> 错误 src\app\admin\customers\customer edit\customer edit.component.html10,97: :类型“string[]”上不存在属性“username”

谢谢。

您已将数据声明为字符串[]字符串数组,但它应为任何类型,并且您正在以data.userName访问该数据的属性


您还需要解析字符串JSON.parse

将'data'变量声明为

data:any;

它将解决您的问题

我也遇到了同样的问题,并通过导入响应解决了问题,
从'@angular/Http'导入{Http,Response}

我们能知道您在本地存储上存储了什么吗?@KShewengger是的,当然,Json数据字符串。您有字符串数组,并且您正在尝试用作对象。请尝试以下操作:数据[0]。用户名而不是数据。用户名。或将数据:字符串[]更改为数据:任意;。
<legend style="align-content:center">Edit Customer</legend>
    <div class="col-lg-12">
         <form class="text-center border border-light p-5">
                <div class="row col-md-12">
                            <label class="col-md-4" style="text-align:right;font-size:20px">Username</label>
                            <label class="col-md-6 mb-4" style="text-align:left;font-size:20px">{{data.username}}</label>
                        </div>
                        <div class="row col-md-12">
                            <button class="btn btn-info col-md-4" type="submit" (click)="updateProfile(data)">Update</button>
                            <div class="col-1"></div>
                            <button class="btn btn-danger col-md-4" type="submit" (click)="navigateCancle()" >Cancle</button>
                        </div>
                    </form>
                </div>
data:any;