Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.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 6中将数组元素的值打印为alert_Angular_Typescript_Data Binding - Fatal编程技术网

如何在angular 6中将数组元素的值打印为alert

如何在angular 6中将数组元素的值打印为alert,angular,typescript,data-binding,Angular,Typescript,Data Binding,我正在控制台上记录来自后端的数组的第0个元素的值 我的问题是如何使用该值并在html页面上打印警报消息 从'@angular/core'导入{Component,OnInit}; 从“../../services/register.service”导入{RegisterService}; 从'@angular/Router'导入{Router}; @组成部分({ 选择器:“应用程序寄存器”, templateUrl:“./register.component.html”, 样式URL:['./

我正在控制台上记录来自后端的数组的第0个元素的值

我的问题是如何使用该值并在html页面上打印警报消息

从'@angular/core'导入{Component,OnInit};
从“../../services/register.service”导入{RegisterService};
从'@angular/Router'导入{Router};
@组成部分({
选择器:“应用程序寄存器”,
templateUrl:“./register.component.html”,
样式URL:['./register.component.css']
})
导出类RegisterComponent实现OnInit{
模型:any={};
瓷砖=[
{文本:“四”,列:2,行:1,颜色:'#DDBDF1'}
];
构造函数(私有身份验证:注册服务,私有路由器:路由器){}
恩戈尼尼特(){
}
注册服务器(事件){
console.log(事件);
event.preventDefault()
常量错误=[]
const target=event.target
const username=target.querySelector('#username').value
const email=target.querySelector(“#email”).value
const dob=target.querySelector(“#date”).value
const password=target.querySelector(“#password”).value
var检验;
此.auth.registerUser(用户名、电子邮件、dob、密码)。订阅(数据=>{
控制台日志(数据);
如果(数据[0]。成功){
console.log(数据[0].success)//此数据[0]我需要在html页面上
}否则{
}
})
console.log(用户名、电子邮件、dob、密码)
}

}
您需要将数据与某个变量绑定,然后才能像这样访问视图-

this.auth.registerUser(username,email,dob, password).subscribe(data => {
        console.log(data);
        if(data[0].success) {
            this.yourData = data[0].success // this data[0] i need to be on html page
        }else{
        }
      });
{{yourData}}
并像这样在HTML中绑定表达式-

this.auth.registerUser(username,email,dob, password).subscribe(data => {
        console.log(data);
        if(data[0].success) {
            this.yourData = data[0].success // this data[0] i need to be on html page
        }else{
        }
      });
{{yourData}}