Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.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
赋值表达式的左侧必须是angular2中的变量或属性访问_Angular - Fatal编程技术网

赋值表达式的左侧必须是angular2中的变量或属性访问

赋值表达式的左侧必须是angular2中的变量或属性访问,angular,Angular,我面临一个错误,说 The left-hand side of an assignment expression must be a variable or a property access. 有了这套代码,我面临着这个错误,有人能解决这个问题吗 this.isDeviceType=navigator.userAgent.match(/iPad/i)!=空?==“iPad”? “iOS”:navigator.userAgent.match(/iPhone/i)!=空?=“iPhone”?

我面临一个错误,说

 The left-hand side of an assignment expression must be a variable or a property access.
有了这套代码,我面临着这个错误,有人能解决这个问题吗

this.isDeviceType=navigator.userAgent.match(/iPad/i)!=空?==“iPad”?
“iOS”:navigator.userAgent.match(/iPhone/i)!=空?=“iPhone”?
“iOS”:navigator.userAgent.match(/Android/i)!=空?==
“安卓”?
“Android”:navigator.userAgent.match(/BlackBerry/i)!=空?=“黑莓”?

“BlackBerry”:“Browser”
您正在将数组与字符串进行比较。 您可以使用
test
而不是
match
var isDeviceType=(/iPad/i).test(navigator.userAgent)?
“iOS”:(/iPhone/i).test(navigator.userAgent)?
“iOS”:(/Android/i).test(navigator.userAgent)?
“Android”:(/BlackBerry/i).test(navigator.userAgent)?
“黑莓”:“浏览器”;

log(isDeviceType)
您正在将数组与字符串进行比较。 您可以使用
test
而不是
match
var isDeviceType=(/iPad/i).test(navigator.userAgent)?
“iOS”:(/iPhone/i).test(navigator.userAgent)?
“iOS”:(/Android/i).test(navigator.userAgent)?
“Android”:(/BlackBerry/i).test(navigator.userAgent)?
“黑莓”:“浏览器”;

console.log(isDeviceType)
String.match
提供实际匹配的数组,如果找不到,则为null

因此,请使用以下模式:

navigator.userAgent.match(/.../i) != null ? "..." : ...

String.match
提供一个实际匹配的数组,如果找不到,则为null

因此,请使用以下模式:

navigator.userAgent.match(/.../i) != null ? "..." : ...

错误TS2365:运算符“==”不能应用于类型“RegExpMatchArray”和“string”。请尝试“==”替代错误TS2365:运算符“==”不能应用于类型“RegExpMatchArray”和“string”。请尝试“==”替代感谢您的响应,我是否应该包括!=到处都是空的?是的,因为每个匹配都应该在不为空的情况下进行测试。@回调的解决方案更好。谢谢您的回复,我应该包括吗!=处处为空?是的,因为每个匹配项都应该在不为空的情况下进行测试。@回调的解决方案无论如何都更好。