首页 \ 问答 \ ng-repeat中的angular Infinite $ digest循环(angular Infinite $digest Loop in ng-repeat)

ng-repeat中的angular Infinite $ digest循环(angular Infinite $digest Loop in ng-repeat)

我想在ng-repeat属性中调用函数,这是我的代码

例如plnkr

HTML

<body ng-controller="mainCtrl">
  <div ng-repeat='item in getGroupedRange() track by item.id'>
    <span>{{item.val}}</span>
    <span>{{item.abs}}</span>
    <span>{{item.rel}}</span>
    <span>{{item.cum}}</span>
  </div>
</body>

JS

$scope.getGroupedRange = function() {
    return [
      {
        val: 1,
        abs: 1,
        rel: 1,
        cum: 1,
        id: 123456
      }
    ];
  };

当我打开控制台时,我注意到了错误

10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":9,"oldVal":8}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":10,"oldVal":9}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":11,"oldVal":10}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":12,"oldVal":11}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":13,"oldVal":12}]]

我的代码的主要目标是使用ng-repeat中的函数来计算每个事件循环中的数据


I want to call function in ng-repeat attribute, here is my code

example plnkr

html

<body ng-controller="mainCtrl">
  <div ng-repeat='item in getGroupedRange() track by item.id'>
    <span>{{item.val}}</span>
    <span>{{item.abs}}</span>
    <span>{{item.rel}}</span>
    <span>{{item.cum}}</span>
  </div>
</body>

js

$scope.getGroupedRange = function() {
    return [
      {
        val: 1,
        abs: 1,
        rel: 1,
        cum: 1,
        id: 123456
      }
    ];
  };

When I opened console I noticed the error

10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":9,"oldVal":8}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":10,"oldVal":9}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":11,"oldVal":10}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":12,"oldVal":11}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":13,"oldVal":12}]]

The main goal of my code is using function in ng-repeat for calculating data in each event loop


原文:https://stackoverflow.com/questions/33847336
更新时间:2022-08-25 13:08

最满意答案

首先,添加一些错误检查。 测试输入后wcin.good()返回的内容以及wcout.good()在“你输入”打印后返回的内容是什么? 我怀疑其中一个会返回false

您的LANGLC_*环境变量设置为什么?

然后尝试通过在 main()的顶部添加它来解决这个问题: wcin.imbue(std::locale("")); wcout.imbue(std::locale("")); wcin.imbue(std::locale("")); wcout.imbue(std::locale(""));

我现在手边没有我的Ubuntu,所以我在这里失明并大多猜测。

UPDATE

如果上面的建议没有帮助,那么尝试构建这样的语言环境,并改为使用imbue()这个语言环境。

std::locale loc (
    std::locale (),
    new std::codecvt_byname<wchar_t, char, std::mbstate_t>("")));

更新2

这对我有用。 关键是也要设置C语言环境。 恕我直言,这是GNU C ++标准库实现中的一个错误。 除非我弄错了,设置 std::locale::global(""); 还应该设置C库语言环境。

#include <iostream>
#include <locale>
#include <clocale>

#define DUMP(x) do { std::wcerr << #x ": " << x << "\n"; } while (0)

int main(){
    using namespace std;

    std::locale loc ("");
    std::locale::global (loc);
    DUMP(std::setlocale(LC_ALL, NULL));
    DUMP(std::setlocale(LC_ALL, ""));    
    wcin.imbue (loc);

    DUMP (wcin.good());
    wchar_t aChar = 0;
    wcin >> aChar;
    DUMP (wcin.good());
    DUMP ((int)aChar);
    wcout << L"You entered " << aChar << L" .\n";

    return 0;
}

更新3

我很困惑,现在我再也无法重现它并设置std::locale::global(loc); 似乎做了正确的事情wrt / C语言环境。


First, add some error checking. Test what does wcin.good() return after the input and what does wcout.good() return after the "You entered" print? I suspect one of those will return false.

What are your LANG and LC_* environment variables set to?

Then try to fix this by adding this at the top of your main(): wcin.imbue(std::locale("")); wcout.imbue(std::locale(""));

I do not have my Ubuntu at hand right now, so I am flying blind here and mostly guessing.

UPDATE

If the above suggestion does not help then try to construct locale like this and imbue() this locale instead.

std::locale loc (
    std::locale (),
    new std::codecvt_byname<wchar_t, char, std::mbstate_t>("")));

UPDATE 2

Here is what works for me. The key is to set the C locale as well. IMHO, this is a bug in GNU C++ standard library implementation. Unless I am mistaken, setting std::locale::global(""); should also set the C library locale.

#include <iostream>
#include <locale>
#include <clocale>

#define DUMP(x) do { std::wcerr << #x ": " << x << "\n"; } while (0)

int main(){
    using namespace std;

    std::locale loc ("");
    std::locale::global (loc);
    DUMP(std::setlocale(LC_ALL, NULL));
    DUMP(std::setlocale(LC_ALL, ""));    
    wcin.imbue (loc);

    DUMP (wcin.good());
    wchar_t aChar = 0;
    wcin >> aChar;
    DUMP (wcin.good());
    DUMP ((int)aChar);
    wcout << L"You entered " << aChar << L" .\n";

    return 0;
}

UPDATE 3

I am confused, now I cannot reproduce it again and setting std::locale::global(loc); seems to do the right thing wrt/ the C locale as well.

相关问答

更多
  • 如果intérêt显示为intérêt 确保标题的格式正确,并将内容呈现为UTF-8编码。 If intérêt shows up as intérêt you likely (i.e. short of corruption due to double encoding) have UTF-8 encoded text being shown up as if it were ISO-8859-1. Make sure the headers are correctly formed and pr ...
  • 我使用此内容在latin1( ISO-8859-1 )中创建了一个名为latin1.xml的特定文件(您可以在xml标记中添加encoding="UTF-8" ,它是相同的): çùé$ °à §çòò àù§ 124 然后我将内容加载到php文件中并从IS ...
  • 此示例调用未定义的行为。 operator<<(std::wostream&,const wchar_t*)期望缓冲区为空终止,并在到达第一个L'\0'字符时停止打印字符。 如果缓冲区恰好包含空字符( L'\0' ),则代码将“正确”运行(尽管输出是不可预测的)。 如果没有,那么operator<<将继续读取内存直到遇到内存。 您的示例不强制存在空终止符。 相比之下,下面将打印一个未指定数量的字符,很可能是垃圾,但是定义得很好: WCHAR wArray[1024]; wArray[1023] = L'\0 ...
  • 问题得到解决,对于阿拉伯字符来说这是一个hibernate问题,我必须像这样编辑我的jdbc网址 jdbc:mysql://localhost:3306/pagesjaunes?useUnicode=true&characterEncoding=UTF-8 而且我必须在ajax函数中设置type : 'post' 。 对于ajax调用中的法语字符,我必须将我的js文件类型修改为utf-8 ,右键单击eclipse中的js文件 - >特性。 PS修改后我必须再次检查我的js文件并修复错误的法语字符;) 如果 ...
  • 尝试这个, function si(condition) { return { alors: function(callback) { if (condition) callback(); return this; }, sinon: function(callback) { if (!condition) callback(); return this; ...
  • 我通常做这样的str_replace (对于德语,因为我不知道新鲜)。 $date = str_replace( array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'), array('Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Jul ...
  • 首先,添加一些错误检查。 测试输入后wcin.good()返回的内容以及wcout.good()在“你输入”打印后返回的内容是什么? 我怀疑其中一个会返回false 。 您的LANG和LC_*环境变量设置为什么? 然后尝试通过在 main()的顶部添加它来解决这个问题: wcin.imbue(std::locale("")); wcout.imbue(std::locale("")); wcin.imbue(std::locale("")); wcout.imbue(std::locale("")); 我现 ...
  • std::wcout << content; 这实际上是调用std::wostream::operator<<(const wchar_t *) 。 它不知道content不是以␀结尾的字符串。 事实上,它不可能知道它在第一种情况下有效长度为4096而在第二种情况下有一些量(你没有保存fgetswc的返回值)。 std::wcout << content; This is effectively calling std::wostream::operator<<(const wchar_t *). It ...
  • 您在函数generateLetter代码始终打印B 您需要将指示当前步骤的参数传递给函数。 尝试这个: def generateLetter(i): print(chr(ord('A') + i)) def main(): ... for each in range(howMany): generateLetter(each) ... You code in function generateLetter always print B. You n ...
  • 为了给你高层次的想法: 您在翻译词典中使用英语单词作为键来获得该单词的法语版本: >>> dictionary_of_words = {"yes":"oui", "no":"non"} >>> dictionary_of_words["yes"] 'oui' >>> 因此,当您读取一个单词作为输入时,检查它是否包含在字典的键列表中,如果是,则打印翻译,否则抛出例外。 要迭代字典,循环键也可以: >>> list_keys = dictionary_of_words.keys() >>> list_keys ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。