角度错误:赋值表达式的左侧必须是变量或属性访问 [英] Angular error: The left-hand side of an assignment expression must be a variable or a property access

查看:94
本文介绍了角度错误:赋值表达式的左侧必须是变量或属性访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不了解或不知道如何解决此错误.

Do not understand or know how to fix this error.

这是代码.我认为这似乎与pushItem函数有关.

This is the code. It seems to be something to do with pushItem function i think.

> **app.component.ts**

import { Component, NgModule } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  //bind this array to li in html
  items = ['Sistema', 'Playstation', 'Web'];

  newItem = '';

  pushItem = function() {
    if(this.newItem ! = ''){
      this.items.push(this.newItem);
      this.newItem = '';
    }
  }


}

@import '~font-awesome/css/font-awesome.css';

.main{
    width: 500px;
    text-align: center;
    margin: 0 auto;
    border: 2px solid #d7d7d7;
    border-bottom: 0px;
    margin-top: 20px;
    font-family: sans-serif;
}

h1{
    text-align: center;
    background-color: #5c8297;
    padding: 30px 0px;
    margin-top: 0px;
    color: #f7f7f7;
}

.addItem{
    position: relative;
    padding-bottom: 0px;
    height: 30px;
}

.addText{
    width: 80%;
    height: 30px;
    padding: 5px;
    font-size: 20px;
}

 button{
    height: 45px;
    width: 50px;
    padding: 5px;
}

ul{
    list-style: none;
    font-size: 20px;
    color: #686868;
    margin-left: -40px;
    margin-bottom: 0px;
}

li{
    border-bottom: 1px solid #bfbfbf;
    background: #d7d7d7;
    padding: 10px 0px;
    margin-bottom: 5px;
}

span{
    cursor: pointer;
    position: relative;
    float: right;
    margin-right: 15px;
}

> **app.component.html**

<div class = 'main'> 
  <h1>Item List</h1>
  <div class = 'add'>
    <input [(ngModel)] = 'newItem' placeholder="add item" class = 'addText'>
    <button>Add</button>
  </div>
  <ul>
    <Li *ngFor = 'let i of items'>
      {{i}} 
      <span><i class="fa fa-times" aria-hidden="true"></i></span>
    </Li>
  </ul> 
</div>

推荐答案

我认为您应该替换

if(this.newItem ! = ''){

通过

if(this.newItem != ''){

之间有一个空格!和=

There is a space between ! and =

这篇关于角度错误:赋值表达式的左侧必须是变量或属性访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆