【发布时间】:2016-03-17 04:56:43
【问题描述】:
我的最终目标是创建一个具有可排序列的表。我目前正在关注一个教程并尝试将其应用到我的项目中,但我的代码设置方式似乎无法正常工作。我还没有找到很多与我使用 Flask 和 Angular 的用例相交的教程。
我现在遇到的问题是范围在我定义控制器的位置结束。我需要将烧瓶模板系统定义的项目添加到角度模型中。
我的烧瓶应用程序正在返回模板系统 (Jinja2) 使用的 json。这是我的html文件。你可以看到我已经尝试通过 ng-model 为艺术家字典中的每个艺术家定义一个“艺术家”模型。
<div class="artist-table-container" ng-controller="ArtistTableCtrl">
<table class="table artist">
<tr>
<th class="artist-table-header"></th>
<th class="artist-table-header">Artist Name</th>
<th class="artist-table-header">Number of Albums Released</th>
<th class="artist-table-header">Most Recent Album</th>
<th class="artist-table-header">Top Track</th>
</tr>
{% for artist in artists%}
<tr ng-model="artist">
<td><div class="artist-img-sml"><img class="artist-cover-sml" src="imgs/cover.png" height="64" width="64"><img src={{artist.col_img}} height="64" width="64"></div></td>
<td>{{artist.name}}</td>
<td>{{artist.num_albums}}</td>
<td>{{artist.last_album}}</td>
<td>{{artist.top_track}}</td>
</tr>
{% endfor %}
</table>
</div>
明显的脱节似乎是我使用的是模板而不是 ng-repeat。 但是,有没有一种方法可以在事后将这些艺术家 html 元素添加到模型中,而不是使用 ng-repeat?
这是我定义的“ArtistTableCtrl”控制器...
/* Controllers */
var sweetMusicApp = angular.module('sweetMusicApp', []);
sweetMusicApp.controller('ArtistTableCtrl', function($scope){
console.log($scope.artist);
console.log($scope);
});
和控制台输出(不出所料)...
undefined
b {$$childTail : null, $$childHead: null, $$nextSibling:null,
$$watchers: null, $$listeners:Object...}
【问题讨论】:
标签: javascript python angularjs flask