ng-model值未在angular指令中显示

时间:2015-02-03 18:56:52

标签: javascript angularjs angularjs-directive

我有一个数据插入的角度指令。现在我想使用相同的角度指令进行数据编辑/更新,但我的问题是,输入值未显示在输入文本字段中。我的代码如下:

指令(js):

  dirApp.directive("inputDesign", function () {
    return {
       restrict: 'E',
       transclude: true,
       replace: true,
       scope: {
          inputName: '@',
          inputNameText: "@",
          inputValue: '@',
          inputObject: '=',
          checkInput: '&'
       },
       templateUrl: '../../template/_inputDesign.php'       
    };
});

模板 _inputDesign.php

<div class="form-group">
    <!-- {{inputObject[name]}} and {{inputValue}} value is not shown -->
    <input type="text" value="{{inputObject[name]}}"  class="form-control" ng-model="inputObject[name]" name="{{inputName}}" placeholder="Enter {{inputNameText}}">

 </div>

html code ::

  <input-design
        input-name="a_gradeName"
        input-name-text="Grade Name"
        input-value="some value" // not work
        input-object="gradeTbl.gradeName"
        check-input="checkInput(gradeTbl.gradeName, gradeTbl.gradeName[name])">
  </input-design>

js code ::

/* grade model */
$scope.gradeTbl = {
  'gradeName': {
      'name': 'a_gradeName',
      'a_gradeName': 'some value',
      'display': 'Grade Name',
      'status': 'initial',
      'regExpr': 'Alphanumeric'
    }
 };

 $scope.gradeTbl.gradeName.a_gradeName = "this is test";   // not worked
 $scope.gradeTbl.gradeName.name= "this is test x";

2 个答案:

答案 0 :(得分:0)

我最好的猜测是与这一点有关:

scope: { inputName: '@', inputNameText: "@", inputValue: '@', inputObject: '=', checkInput: '&' },

我会尝试将inputValue更改为

inputValue: '=',

以下是关于范围内=和@之间差异的另一个答案。

What is the difference between '@' and '=' in directive scope in AngularJS?

答案 1 :(得分:0)

在您的_inputDesign.php中,将值和ng-model从{{inputObject[name]}}更改为inputObject.name