NG-模式已不再更新,输入到文本输入后 [英] ng-model no longer updates after typing into text input

查看:126
本文介绍了NG-模式已不再更新,输入到文本输入后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来AngularJS,我具有我有麻烦解决一个问题,有计算器上过类似的问题,但它似乎并没有帮助我。我基本上是被吴点击更新的一种形式,但一旦当我文本输入到任何的文本框,这些文本框不再更新。

这是我的HTML

 编辑课程:
<李NG重复=培训课程>
  &所述p为H.;
    &下;一个纳克单击=Edit_Course(course.id)> {{course.course_name}}&下; / A>
  &所述; / P>
< /李>
< D​​IV NG秀=showedit == 1>
  <形式的novalidate NG提交=edit_course()级=简单形式>
    <标签=form_course_name>课程和LT; /标签>
      <输入类型=文本ID =form_course_nameNG模型=edit_course_name>
    <标签=form_par>&标准杆LT; /标签>
      <输入类型=文本ID =form_parNG模型=edit_course_par>
    <标签=form_course_location>当然位置和LT; /标签>
      <输入类型=文本ID =form_course_locationNG模型=edit_course_location>
     <输入类型=提交ID =提交值=编辑课程/>
   < /表及GT;
< / DIV>

结果
结果
这是我的功能,当有人点击一个链接被称为

  $ scope.Edit_Course =功能(ID){
    VAR当然= {
        COURSE_ID':ID
    };    $ HTTP({方法:POST,网址:http://www.dgcharts.com/editcourse数据:当然})
    .success(功能(数据,状态,头,配置){      thecourse =数据[当然];
      $ scope.edit_course_name = thecourse.course_name;
      $ scope.edit_course_par = thecourse.par;
      $ scope.edit_course_location = thecourse.course_location;
      $ scope.edit_course_id = thecourse.id;
      $ scope.showedit = 1;
  })
}


解决方案

你的链接需要登录。

如果我必须去猜测你的问题,这可能与角度范围界定问题。尝试改变你的NG-模型绑定到一个对象属性。所以在你的HTML,而不是:

 <输入类型=文本ID =form_course_nameNG模型=edit_course_name>

做到这一点。

 <输入类型=文本ID =form_course_nameNG模型=course.edit_course_name>

和在你的JavaScript,Ajax的回调,将其更改为:

  $ scope.course = {}; //只有这样做,如果$ scope.course尚未宣布
$ scope.course.edit_course_name = thecourse.course_name;

有关此问题的详细信息,请参见:<一href=\"https://github.com/angular/angular.js/wiki/Understanding-Scopes\">https://github.com/angular/angular.js/wiki/Understanding-Scopes

I am new to AngularJS and I am having a problem that I am having trouble solving, there was a similar question on stackoverflow but it didn't seem to help me out. I basically have a form that gets updated by ng-click, but once once I enter text into any of the text boxes, those text boxes no longer update.

This is my HTML

Edit Course:
<li ng-repeat="course in courses">
  <p>
    <a ng-click="Edit_Course(course.id)">{{course.course_name}}</a>
  </p>
</li>
<div ng-show="showedit == 1">
  <form novalidate ng-submit="edit_course()" class="simple-form">
    <label for="form_course_name">Course</label>
      <input type="text" id="form_course_name" ng-model="edit_course_name">
    <label for="form_par">Par</label>
      <input type="text" id="form_par" ng-model="edit_course_par">
    <label for="form_course_location">Course Location</label>
      <input type="text" id="form_course_location" ng-model="edit_course_location">
     <input type="submit" id="submit" value="Edit Course" />
   </form>
</div>



This is my function that is called when someone clicks on a link

$scope.Edit_Course = function (id) {
    var course = {
        'course_id' : id
    };

    $http({method: "POST", url: "http://www.dgcharts.com/editcourse", data: course})
    .success(function(data, status, headers, config){

      thecourse = data["course"];
      $scope.edit_course_name = thecourse.course_name;
      $scope.edit_course_par = thecourse.par;
      $scope.edit_course_location = thecourse.course_location;
      $scope.edit_course_id = thecourse.id;
      $scope.showedit = 1;
  })
}

解决方案

your link requires a login.

if i have to guess about your problem, it may be related to angular scoping issue. try changing your ng-model binding to an object property instead. so in your html, instead of:

<input type="text" id="form_course_name" ng-model="edit_course_name">

do this

<input type="text" id="form_course_name" ng-model="course.edit_course_name">

and in your javascript, on the ajax callback, change it to:

$scope.course = {};  //only do this if $scope.course has not already been declared
$scope.course.edit_course_name = thecourse.course_name;

for more info on this issue, see: https://github.com/angular/angular.js/wiki/Understanding-Scopes

这篇关于NG-模式已不再更新,输入到文本输入后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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