I have a template with an ng-if
that checks if something is an array and an inner ng-repeat that loops over it and re-applies the same template. Otherwise if its a string it just prints the value.
Unfortunately, it seems ng-if
(600) has a lower priority than ng-repeat
(1000), so even with strings, the ng-repeat just calls the template over and over again (I guess with each letter of the string) and hangs the browser.
Any ideas on how to make the ng-if
run in higher priority? Or any other nice way to accomplish this?
Directive
app.directive('cell', function ()
{
return {
restrict: "AE",
scope: {
cellData: '=cellData'
},
link: function (scope, element, attrs)
{
scope.isString = function (str)
{
return angular.isString(str);
};
scope.isArr = function (arr)
{
return !angular.isString(arr) && angular.isArray(arr);
};
},
transclude: true,
templateUrl: function (elem, attrs)
{
return "/template/cellData";
}
}
Template
span(ng-if='isArr(cellData)')
| [
span(ng-repeat='inner in cellData')
cell(cellData='inner')
span(ng-if='!$last') , 
| ]
span(ng-if='!isArr(cellData)')
span(ng-bind="isString(cellData) ? '\"'+cellData+'\"' : cellData")
EDIT: I solved the problem using the code from this question. I don't really get it, but I'm happy it works.