AngularJS ng-hide出错

时间:2013-09-09 19:19:46

标签: angularjs angularjs-directive

显然我不完全理解Angular的ng-show指令如何与$ scope交互。我想在数组为空时隐藏元素。我的HTML如下:

<h1>Tabs</h1>
<ul ng-hide="tabs.length == 0">
    <li ng-repeat="t in tabs">
        <img src="{{t.thumbnailurl}}" />
    </li>
</ul>

标签是这样的:

Array
    0: Object
        $$hashKey: "01H"
        created: "2013-08-20 20:15:00"
        thumbnailurl: "https://s3.amazonaws.com/xxxxx"
        __proto__: Object
    1: Object
        $$hashKey: "01J"
        created: "2012-07-09 23:26:49"
        thumbnailurl: "https://s3.amazonaws.com/xxxxx"
        __proto__: Object
    length: 2
    __proto__: Array[0]

当我加载页面时,ng-hide在控制台中抛出以下异常,说明匿名函数没有方法'trim'。很明显,Angular正在内部的某个地方徘徊。

TypeError: Object function () {

// If the string looks like an identifier, then we can return it as is.
// If the string contains no control characters, no quote characters, and no
// backslash characters, then we can simply slap some quotes around it.
// Otherwise we must also replace the offending characters with safe
// sequences.


        if (ix.test(this)) {
            return this;
        }
        if (/[&<"\/\\\x00-\x1f]/.test(this)) {
            return '"' + this.replace(/[&<"\/\\\x00-\x1f]/g, function (a) {
                var c = escapes[a];
                if (c) {
                    return c;
                }
                c = a.charCodeAt();
                return '\\u00' +
                    Math.floor(c / 16).toString(16) +
                    (c % 16).toString(16);
            }) + '"';
        }
        return '"' + this + '"';
    } has no method 'trim'
    at watchFnToHumanReadableString (http://b.gro/campaigns#/tabs/23402:706:30)
    at Object.$delegate.__proto__.$watch (http://b.gro/campaigns#/tabs/23402:735:28)
    at http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:13829:9
    at nodeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:4406:13)
    at compositeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:4015:15)
    at publicLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:3920:30)
    at <error: illegal access>
    at Object.Scope.$broadcast (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:8307:28)
    at http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:7463:26
    at wrappedCallback (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:6846:59) <ul ng-hide="tabs.length == 0" class="ng-scope"> angular.js:5754

根据ng-hide / show docs,这个指令应该非常直接,并接受传递给它的truthy / falsy语句。我只是不确定我在这里做错了什么......

1 个答案:

答案 0 :(得分:4)

所以,得到这个。在注意到这在FF中正确触发后,我开始禁用Chromium中的扩展。一旦我禁用了角度调试器插件,就会变成:https://chrome.google.com/webstore/detail/angularjs-batarang/ighdmehidhipcmcojjgiloacoafjmpfk,它正确触发!