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



我遇到一个错误说

The left-hand side of an assignment expression must be a variable or a property access.

有了这组代码,我面临这个错误,任何人都可以解决这个问题。

this.isDeviceType = navigator.userAgent.match(/iPad/i)!= null ? ===  "iPad" ?
"iOS" : navigator.userAgent.match(/iPhone/i)!= null ?=== "iPhone" ? 
"iOS" : navigator.userAgent.match(/Android/i)!= null ? === 
"Android" ? 
"Android" : navigator.userAgent.match(/BlackBerry/i)!= null ?=== "BlackBerry" ? 
"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) ?
"BlackBerry" : "Browser";
console.log(isDeviceType)

String.match提供实际匹配的数组,如果未找到任何匹配项,则为 null。

因此,请使用以下模式:

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

最新更新