加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – Angular TypeError:无法在字符串”上创建属性

发布时间:2020-12-17 08:52:49 所属栏目:安全 来源:网络整理
导读:单击“添加”后尝试清除输入框,就像这个人在 this tutorial中所做的那样. 我使用这个简短的代码重新创建了错误,而没有使用API??. 您还可以查看 Plunker. HTML input ng-model="contact.name" type="text"button ng-click="Add()"Add/buttonul ng-repeat="con
单击“添加”后尝试清除输入框,就像这个人在 this tutorial中所做的那样.
我使用这个简短的代码重新创建了错误,而没有使用API??.
您还可以查看 Plunker.

HTML

<input ng-model="contact.name" type="text">
<button ng-click="Add()">Add</button>

<ul ng-repeat="contact in contactList">
    <li>{{ contact.name }}</li>
</ul>

JS

$scope.contactList = [
    {name: 'cris'},{name: 'vlad'}
;]

$scope.Add = function() {
    $scope.contactList.push($scope.contact)
    $scope.contact = ""
}

似乎我可以添加1项,但在第二个我得到此错误:

您没有以正确的方式清理联系人对象.在Add()函数中,更改:
$scope.contact = ""

至:

$scope.contact = {};

Forked Plunker

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读