Issue with ng-repeat Directive
I have encountered a problem where the ng-repeat directive does not track the addition of a new array, specifically 'options'. This issue arises when the directive is used within a template displayed using ng-dialog from a third-party library. Oddly enough, if I close the dialog box and reopen it, the changes made before closing are picked up by ng-repeat.
Attempting to use $scope.$apply(); resulted in a warning stating that it was already running.
Solution ++
To overcome this obstacle, I implemented a solution where a function was added to the ng-init attribute to first check for the existence of the array. If the array did not exist, it was created and then assigned to the new variable.
Here's a more detailed example:
After creating this jsFiddle, I discovered that the issue lies within the ng-include/ng-repeat - without these components, everything works fine.
http://jsfiddle.net/20mobk2h/56/
http://jsfiddle.net/20mobk2h/61/
The ng-repeat iterates over an array named options, which may or may not exist.
<div ng-init="options = element.options">
<div ng-repeat="option in options" ng-include="'optionsTree'"></div>
</div>
To add a new option:
$scope.addItem = function(item) {
if(!item.options){
item.options = [];
}
var obj = {
val: 'blah'
};
item.options.push(obj);
}