Angular ng-repeat works..但是没有值被绑定/显示(小枝)
Angular ng-repeat works... but no values are bound / displayed (Twig)
我在启动新的Angular项目时遇到了一些问题。我将在稍后将其分解为服务等,但现在我只在一个名为sandpiper
的模块中有一个名为DashCtrl
的控制器。
我想从DashCtrl
中的$scope.results
数组中创建div.card
元素列表,当单击add-button
时,附加项附加到$scope.results
,并将其$scope.test
附加到标题。点击按钮几次后发生的事情是这样的:(截图链接,因为我是新人,没有声望点T_T)
$scope.pushit()
works和ng-repeat
最终吐出了适当数量的项目,但没有标题。$scope.test
也没有被读取。我已经绞尽脑汁好几个小时了,甚至编写了一个简单的Angular测试,以确保我没有发疯……但是我就是想不明白这个。
这是我的JS(两个脚本,缩小到/build/sandpiper.min.js
后)
var app = angular.module('sandpiper', []);
app.controller('DashCtrl',['$scope',function($scope){
$scope.test = "Header"
$scope.results = [
{
title: "Test Item 1",
file: "12345978-My-Test-Document.pdf",
type: "PDF",
tags: ['pdf','test','foo','bar'],
image: "static/img/pdf.png"
}
]
$scope.pushit = function(){
$scope.results.push({
title: "Test Item 1",
file: "12345978-My-Test-Document.pdf",
type: "PDF",
tags: ['pdf','test','foo','bar'],
image: "static/img/pdf.png"
})
}
}])
这是我的HTML(不相关的部分省略)
<!DOCTYPE html>
<html lang="en">
<head>
(...)
<!-- bower:js -->
<script src="../bower_components/jquery/dist/jquery.js"></script>
<script src="../bower_components/materialize/bin/materialize.js"></script>
<script src="../bower_components/angular/angular.js"></script>
<!-- endbower -->
<script src="/build/sandpiper.min.js"></script>
</head>
<body ng-app="sandpiper">
<main>
<div class="container" id="content-root">
<div id="dash-wrapper" ng-controller="DashCtrl">
<h3>Test {{ test }}</h3>
<a ng-click="pushit()" class="btn-floating btn-large waves-effect waves-light" id="add-button">
<i class="material-icons">add</i>
</a>
<nav>
(...)
</nav>
<div class="row" id="results-container">
<div class="col s12 m4 l3" ng-repeat="item in results">
<div class="card">
<div class="card-content">
<span class="black-text">{{ item.title }}</span>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
(...)
</body>
</html>
任何帮助将非常感激;提前感谢。希望这不是什么非常愚蠢的事情……
嗯…这个问题很明显。我挑出了我的CSS包含(我使用的是Materialize),并确定这不是问题所在——实际上是我使用了Twig,这是一个PHP模板引擎,也使用了小胡子符号来表示变量。我的绑定甚至在到达浏览器之前就被后端剥离了。真不敢相信我竟然没意识到。
对于其他有此问题的人,请尝试使用不同的Angular分隔符或为Twig使用不同的tag_variable
模式。
相关文章:
- 有没有比在app.js上绑定模块名称更好的方法来动态加载视图模型和视图以显示模态
- 使用AngularJs数据绑定的三元运算符显示图像
- 嵌套的foreach绑定未正确显示
- 敲除:可观察数组没有被正确绑定——只有1个结果显示,而api返回6
- 挖空和显示模块模式的数据绑定问题
- 悬停卡未显示在具有绑定的 KNOCKOUTJ 中
- AngularJs的绑定值未显示
- Angularjs-将指令中的值绑定到文档中的任意位置显示/隐藏
- 使用knockoutjs绑定和显示字典
- angularjs绑定赢得'除非我打GET电话,否则不会显示
- 基本角度(绑定未显示)
- 为什么这个简单的ng绑定和ng显示不起作用
- 显示绑定到动态生成的元素的所有事件处理程序
- 角度 ui-select 绑定到一个属性,但向用户显示另一个属性
- 显示带有角度 js 数据绑定表单的引导框
- 显示具有 MVC 数据绑定视图模型 ASP.NET JQuery 对话框的最佳方式
- 如何通过按钮切换文本区域的显示,使用带有 foreach 绑定的挖空
- 挖空 JS为每个绑定显示 [对象对象]
- Angular JS-{{}}不工作,但数据绑定显示作用域
- Angular ng-repeat works..但是没有值被绑定/显示(小枝)