0

I have an angular directive for data insert. And now I want to use same angular directive for data edit/update, but my problem is, the input value is not shown in the input text field. My code is given below:

directive (js) :

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

template _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";
sabbir
  • 2,020
  • 3
  • 26
  • 48

2 Answers2

0

My best guess is that is has to do with this bit:

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

I would try changing inputValue to

inputValue: '=',

Here is another answer about the difference between = and @ in scope.

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

Community
  • 1
  • 1
peoplespete
  • 1,104
  • 1
  • 11
  • 15
0

In your _inputDesign.php, change value and ng-model from {{inputObject[name]}} to inputObject.name.

brennan
  • 131
  • 5