Javascript 填写模态窗口表格

Javascript 填写模态窗口表格,javascript,angularjs,Javascript,Angularjs,我在填充模式窗口窗体时遇到问题。例如,我单击网格行编辑用户,然后调用ajax,它返回用户的特定数据 当前代码: <modal title="Uredi uporabnika" visible="showModal"> <form role="form"> <div class="form-group"> <label for="user_name">Ime</label>

我在填充模式窗口窗体时遇到问题。例如,我单击网格行编辑用户,然后调用ajax,它返回用户的特定数据

当前代码:

 <modal title="Uredi uporabnika" visible="showModal">
        <form role="form">
          <div class="form-group">
            <label for="user_name">Ime</label>
            <input type="text" class="form-control" id="user_name" />
          </div>
          <button type="submit" class="btn btn-default">Submit</button>
        </form>
 </modal>
模态窗口代码:

app.directive('modal', function(){
  return {
  template: '<div class="modal fade">' + 
      '<div class="modal-dialog">' + 
        '<div class="modal-content">' + 
          '<div class="modal-header">' + 
            '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>' + 
            '<h4 class="modal-title">{{ title}}</h4>' + 
          '</div>' + 
          '<div class="modal-body" ng-transclude></div>' + 
        '</div>' + 
      '</div>' + 
    '</div>',
  restrict: 'E',
  transclude: true,
  replace:true,
  scope:true,
  link: function postLink(scope, element, attrs) {
    scope.title = attrs.title;

    scope.$watch(attrs.visible, function(value){
      if(value == true)
        $(element).modal('show');
      else
        $(element).modal('hide');
    });

    $(element).on('shown.bs.modal', function(){
      scope.$apply(function(){
        scope.$parent[attrs.visible] = true;
      });
    });

    $(element).on('hidden.bs.modal', function(){
      scope.$apply(function(){
        scope.$parent[attrs.visible] = false;
      });
    });
  }
};
});

我非常感谢您的帮助,即使我是Angular的新手,所以我的工作方式正确。

使用输入ID填充值:

$("#user_name").val(data.user_info);

好吧,经过数百万次的尝试,我找到了解决办法,我只是把手放在头上

<input type="text" class="form-control" id="user_name" value="{{userInfo.u_name}}" />
所以我必须添加userInfo对象并调用参数u_name


tnx Shivi仍然需要帮助:D

何时何地调用openUserEditor函数?在第行中单击表“编辑”中的“是否可以检查成功回调中的$scope对象…”。。??有时它被设置为窗口,而不是控制器范围。然后,你可以在api调用之外有一个变量,比如,var self=this,然后使用this.userInfo。我得到了一个在作用域中包含用户信息的对象。我将尝试查看它…:
<input type="text" class="form-control" id="user_name" value="{{userInfo.u_name}}" />