为什么AnguarJS数据绑定不起作用
Why is this AngualrJS data binding not working?
如何创建输出HTML的angularjs过滤器,它看起来像我想要的,但我的版本还不起作用。在我的HTML中,我有:
<ul>
<li ng-repeat="book in books | filter:query">
{{book.title}}
<div ng-bind-html="book.snippet"></div>
</li>
</ul>
但它只显示书名,就好像<div ng绑定html>不在那里。控制器具有所有所需的数据,从开始
$scope.books = [
{
'image': '/images/the_best_of_jonathans_corner_full.jpg',
'snippet': '<p>If you read just one book from this site, <em>The Best of Jonathan''s Corner</em> is a head taller than the others. It contains all of the best works of theology from Jonathan''s Corner, and there''s a lot to dig through—but only if you want. If not, feel free to enjoy and read as little or as much as you like.</p><p>This book is the author''s favorite title out of all the books sold from this site.</p>',
'title': 'The Best of Jonathan''s Corner',
'url': '/redirect/the_best_of_jonathans_corner.html'
},
网页看起来像:
CJS Hayward
Search books:
The Best of Jonathan's Corner
Doxology: The Anthology
The Luddite's Guide to Technology
为什么出现了书的标题,却没有出现小册子?我在一些片段中有HTML,我希望它们将片段呈现为HTML。(我可以有一个转义版本为{{book.sippet}},但我想知道在这里处理HTML(非)转义的正确方法。)所有的代码片段都是作为严格有效的XHTML编写的,并以<p>标签等
该项目旨在成为AngularJS phonecat教程的一部分。
--更新--
谢谢你,@ppa;我已经编辑了源文件,包括:
<script src="/js/angular.min.js"></script>
<script src="/js/angular-sanitize.js"></script>
<script src="/js/controllers.js"></script>
controllers.js现在开始:
'use strict';
var authorApp = angular.module('authorApp', ['ngSanitize']);
AngularJS没有重复任何内容(我在console.log中没有看到任何新内容):
CJS Hayward
Search books:
{{book.title}}
我还应该包括什么?该应用程序当前位于http://new.cjsh.name.
在开发者工具中简要查看了您的代码后,我可以看到您使用的是angular 1.3版(beta5)的angular-splicate.js。但您的angular.js脚本是1.2版。我猜问题出在这个版本不匹配上。请尝试使用相同1.3版本的angular.js脚本,看看这是否有效。你可以在这里找到它。
要使ng-bind-html指令正常工作,必须提供$sance服务。你的应用程序中包含ngSanitize模块和ng-sanise.js脚本了吗?
相关文章:
- $http中的Angular 1数据绑定承诺不起作用
- 对于使用传递的数据计算的局部范围变量,角度绑定在自定义指令中不起作用
- 为什么我的数据绑定到一个计算函数不起作用(使用knockout.js和jade)
- 数据绑定禁用属性在 foreach 内的按钮中不起作用
- 数据绑定在带有输入标签的 AngularJS 中不起作用
- foreach:绑定不起作用 ko.mapping.fromJS 数据
- 数据绑定在特定情况下不起作用(AngularJS)
- Angularjs 双向数据绑定不起作用;$watch也不起作用
- AngularJS:双向数据绑定 - 带有ng重复的指令 - 不起作用
- 使用 D3js 时,带有 DOM 的 AngularJS 数据绑定不起作用
- Angularjs 双向数据绑定不起作用
- AJAX 发布到挖空.js数据绑定不起作用
- 对话数据绑定不起作用
- 绑定数据在 d3.js 中不起作用
- AngularJS数据绑定到按钮不起作用
- 为什么我的数据绑定不起作用
- Vue.js 数据绑定样式背景图像不起作用
- 如何在不破坏角度数据绑定的情况下更新集合中的项
- javascript不会将数据绑定到HTMLSelect元素
- 第一次单击按钮时,它不会将数据绑定到表中