Angular.JS:为什么不能输入编辑吗? [英] Angular.JS: why can't the inputs be edited?

查看:124
本文介绍了Angular.JS:为什么不能输入编辑吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个奇怪的问题。在code是简单的:

This is a strange problem. The code is simple:

HTML code:

HTML code:

<body ng-controller="MainCtrl">
  <ul ng-repeat="name in names">
    <input type="text" ng-model="name" />
  </ul>
</body>

角code:

app.controller('MainCtrl', function($scope) {
    $scope.names = ["aaa","bbb","ccc"];
});

在现场演示网址是:<一href=\"http://plnkr.co/edit/2QFgRooeFUTgJOo223k9?p=$p$pview\">http://plnkr.co/edit/2QFgRooeFUTgJOo223k9?p=$p$pview

我不明白,为什么输入控件不能编辑,我不能键入新的字符或删除字符。

I do not understand why the input controls can not be edited, I can't type new characters or delete characters.

推荐答案

这是由于范围继承的共同课题。每个名称是一个原始,所以 NG-重复使得它是没有连接到原来的自己范围的项目,然而,如果每个名称是一个对象 NG-重复范围的项目将是原来的对象的引用

This is a common issue due to scope inheritance . Each of your names is a primitive so ng-repeat makes it's own scope item that is not connected to original, however if each names is an object ng-repeat scope item will be a reference to original object

 [{name:"aaa"},{name:"bbb"},{name:"ccc"}];

总是使用 NG-模型是一个经验有用的规则

Always use a dot in ng-model is a helpful rule of thumb

<div ng-repeat="item in names">
      <input type="text" ng-model="item.name"/>
    </div>

工作Plunker

阅读这篇文章的角度github上维基详细explanaton:

Read this article on angular github wiki for detailed explanaton:

<一个href=\"https://github.com/angular/angular.js/wiki/The-Nuances-of-Scope-Prototypal-Inheritance\">https://github.com/angular/angular.js/wiki/The-Nuances-of-Scope-Prototypal-Inheritance

这篇关于Angular.JS:为什么不能输入编辑吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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