我将我的angularjs应用程序从1.2.0迁移到1.3.0-rc2,我想将我的代码从bindonce更改为新的一次性绑定.我还使用了角度转换.我写下面的代码:
<span data-ng-bind="::'COMMENT'|translate" />
<span>{{::'COMMENT'|translate}}</span>
<img src="shareBlack.png" alt="{{::'SHARE'|translate}}" data-ng-attr-title="::'SHARE'|translate" data-ng-click="startShare()" />
Run Code Online (Sandbox Code Playgroud)
但在巴塔朗,我可以看到以下手表表达式:
{{::'SHARE'|translate}} | 3.59% | 17.00ms
::'COMMENT'|translate | 2.95% | 14.00ms
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
使用bindonce在以前版本1.2.0中编辑我有以下代码:
<div class="box-container" bindonce>
...
<span data-bo-text="'FEED_ALLOWED_COMMENTS'|translate"/>
...
</div>
Run Code Online (Sandbox Code Playgroud) 我一直在阅读关于bindonce作为减少手表和提高性能的方法.为了更好地理解包装,我做了一个例子ng-repeat.
没有bindonce我得到103个手表,100个列表项+ 2个按钮.
使用bindonce我获得3个手表,2个底部+ 1个列表.
如果我理解binonce正确,它会在解析并渲染绑定对象后删除手表.所以,
如何使用bindonce对对象所做的更改仍然可以反映在DOM中?
让我们假设无限滚动显示的 1000 个项目的列表。
每个项目显示:一个人的名字、姓氏和心情。(为了简单起见)
最初,我不想听更新。
所以伟大的angular-bindonce指令甚至更好:angular 1.3 one-binding 特性成功了。
现在,我创建了一个下拉刷新组件,允许刷新整个项目。
但是,作为一次绑定(而不是重新加载页面),我的整个列表没有考虑更新。
使用 angular-bindonce,我目前有这个:
<div bindonce ng-repeat="person in persons track by person.id">
<span bo-text="person.firstName"></span>
<span bo-text="person.lastName"></span>
<span bo-text="person.currentMood"></span>
</div>
Run Code Online (Sandbox Code Playgroud)
下拉刷新触发此功能:
$scope.refresh() {
Persons.getList(function(response)) {
$scope.persons = response.data; //data being an array
}
}
Run Code Online (Sandbox Code Playgroud)
问题是:
有没有办法仅在触发下拉刷新时刷新所有数据?
在这种情况下,我将能够保持这种单一绑定,这将在处理大量人员列表时大大提高性能。
到现在为止,我不得不……使用双向绑定,这是 Angular 工作的自然方式。
更一般地说,如何处理只有在触发某些事件时才需要更新的无限滚动的巨大列表?
在阅读bindonce指令的文档时,我想知道bo-html和之间有什么区别bo-text.
bo-html: 评估"标记"并将其渲染为元素内的html
bo-text:评估"文本"并将其作为文本在元素内打印
所以,我希望这段代码能够工作:
<span bo-html="<strong>SomeText</strong>"></span>
Run Code Online (Sandbox Code Playgroud)
但我得到了这个:
Error: [$parse:syntax] Syntax Error: Token '<' not a primary expression at column 1 of the expression
Run Code Online (Sandbox Code Playgroud)
<strong>作为一个基本的标记,不是吗?
如果这不起作用(可能是语法问题..),bo-text和之间的真正区别是bo-html什么?
我正在努力提高ng-repeat的性能.我已将项目升级为使用库v1.3.0(主库和路径).
我想一旦这里使用绑定:不要嵌套在一个慵懒的一次NG重复绑定绑定内只有一次绑定?
但是,当我将::添加到我的ng-repeat时,列表未填充:
<li ng-repeat="info in Profile.ChangeInfo">
<p> {[{info.Message}]} </p>
</li>
Run Code Online (Sandbox Code Playgroud)
以上工作.
以下失败:
<li ng-repeat="info in ::Profile.ChangeInfo">
<p> {[{::info.Message}]} </p>
</li>
Run Code Online (Sandbox Code Playgroud)
我看到的错误是:
Error: [$parse:syntax] http://errors.angularjs.org/1.3.0-beta.9/$parse/syntax?p0=%3A&p1=not%20a%20primary%20expression&p2=1&p3=%3A%3AProfile.ChangeInfo&p4=%3A%3AProfile.ChangeInfo
Run Code Online (Sandbox Code Playgroud)
更新 升级到测试版16,现在在IE8中看到此错误:
网页错误详情
用户代理:Mozilla/4.0(兼容; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; MS-RTC LM 8; InfoPath.3)时间戳:星期五,2014年8月15日12:01:03 UTC
Message: [$injector:modulerr] Failed to instantiate module ng due to:
Object doesn't support this property or method
http://errors.angularjs.org/1.3.0-beta.16/$injector/modulerr?p0=ng&p1=Object%20doesn't%20support%20this%20property%20or%20method
Line: 3982
Char: 7
Code: …Run Code Online (Sandbox Code Playgroud) data-binding optimization angularjs angularjs-scope bindonce