1

显然我并不完全理解 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 文档,该指令应该非常直接,并接受传递给它的真/假语句。我只是不确定我在这里做错了什么......

4

1 回答 1

4

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

于 2013-09-09T19:52:25.830 回答