0

I got a html mockup like this:

 <tbody>
                        <tr ng-repeat="row in objectData.Tables[1].Dataset">
                            <td ng-repeat="col in objectData.Tables[1].Columns  | filter:isColumnVisible | filter:skipColumnHiden" ng-click="items.SetSelected(objectData.Tables[1],row.$$hashKey)"
                                ng-class="{'dd-selected': objectData.Tables[1].$ddSelected===row.$$hashKey, 'dd-vh-2':col.Length<=25 , 'dd-vh-5':col.Length>25 && col.Length<=50, 'dd-vh-10':col.Length>50 && col.Length<=100, 'dd-vh-15':col.Length>100 && col.Length<=150, 'dd-vh-20':col.Length>150 && col.Length<=250}">
                                <div ng-switch="col.Type" ng-hide="objectData.Tables[1].$ddSelected===row.$$hashKey || ($index==0 && row.showRowButtons == true)">
                                    <span ng-switch-when="Integer" class="dd-cell">{{row[col.Code] | number}}</span>
                                    <span ng-switch-when="Date" class="dd-cell">{{row[col.Code] | date}}</span>
                                    <span ng-switch-when="DateTime" class="dd-cell">{{row[col.Code] | date}}</span>
                                    <span ng-switch-when="Decimal" class="dd-cell">{{row[col.Code] | number}}</span>
                                    <span ng-switch-when="Currency" class="dd-cell">{{row[col.Code] | currency}}</span>
                                    <span ng-switch-default class="dd-cell">{{row[col.Code]}}</span>
                                </div>
                                <div class="row" ng-show="objectData.Tables[1].$ddSelected===row.$$hashKey" ng-switch="col.Type" style="clear:both" dd-stop-click>
                                    <input ng-switch-when="Integer" class="form-control input-sm" type="number" ng-model="row[col.Code]" ng-required="col.Required" />
                                    <input ng-switch-when="Decimal" class="form-control input-sm" type="number" ng-model="row[col.Code]" ng-required="col.Required" />
                                    <input ng-switch-when="Currency" class="form-control input-sm" type="number" ng-model="row[col.Code]" ng-required="col.Required" />
                                    <input ng-switch-when="Date" class="form-control input-sm" type="date" ng-model="row[col.Code]" ng-required="col.Required" />
                                    <input ng-switch-when="DateTime" class="form-control input-sm" type="datetime" ng-model="row[col.Code]" ng-required="col.Required" />
                                    <input ng-switch-when="Boolean" class="form-control input-sm" type="checkbox" ng-model="row[col.Code]" />
                                    <dd-combo-grid ng-switch-when="Relation" ng-model="row[col.Code]" dd-object="{{col.Class}}" dd-selected="ddSelected(objectId)" dd-template="/Template/Modal/Table"></dd-combo-grid>
                                    <input ng-switch-default class="form-control input-sm" type="text" ng-model="row[col.Code]" ng-required="col.Required" />
                                </div>
                            </td>
                        </tr>
                    </tbody>

The directive making problems is the dd-combo-grid witch looks like this:

var ComboGridDirecitve = function () {
    return {
        restrict: 'E',
        scope: {
            ddObject: '@',
            ddId: '=ngModel',
            ddName: '=',
            ddSelected: '&',
            ddParent:'=',
            ddTemplate: '@',
            globals: '=globals',
            ddReplace: '@'
        },
        require: 'ngModel',
        templateUrl: 'Template/ComboGrid',
        controller: 'ModalObjectController',
        link: function (scope, element, attrs) {
            scope.ddModal = false;
            scope.isChanged = false;
            scope.ddModalTemplate = '';
        }
    }
}

The Directive defines that the ddId has in = binding to ngModel

The problem is that when ddId updates that is not propagated to the ngModel of the directive for some reason

Controler code:

$scope.ddId = r['code'];
console.log('selected Id:', $scope.ddId);

The log returns the correct value.

The same directive works if it is not used in a ngRepeat for some reason

Any ideas?

Jester
  • 3,069
  • 5
  • 30
  • 44
  • because ngRepeat is already directive, and you have to apply your ngModel, to set ngModel in child directive. – Maher May 16 '16 at 12:28
  • [see this article](http://stackoverflow.com/questions/34663047/angularjs-dynamic-directives-using-ng-repeat/34663950#34663950) – Maher May 16 '16 at 12:30
  • sorry did not understand how to adopt '$compile' to '$apply' – Jester May 16 '16 at 13:05

0 Answers0