Angular filter works but causes “10 $digest iterations reached”

前端 未结 7 1408
走了就别回头了
走了就别回头了 2020-11-30 00:56

I receive data from my back end server structured like this:

{
  name : \"Mc Feast\",
  owner :  \"Mc Donalds\"
}, 
{
  name : \"Royale with cheese\",
  owne         


        
7条回答
  •  萌比男神i
    2020-11-30 01:48

    For what it's worth, to add one more example and solution, I had a simple filter like this:

    .filter('paragraphs', function () {
        return function (text) {
            return text.split(/\n\n/g);
        }
    })
    

    with:

    {{ p }}

    which caused the described infinite recursion in $digest. Was easily fixed with:

    {{ p }}

    This is also necessary since ngRepeat paradoxically doesn't like repeaters, i.e. "foo\n\nfoo" would cause an error because of two identical paragraphs. This solution may not be appropriate if the contents of the paragraphs are actually changing and it's important that they keep getting digested, but in my case this isn't an issue.

提交回复
热议问题