【发布时间】:2016-06-22 18:10:30
【问题描述】:
我正在尝试向表中添加一行“isrcrow”指令,如下所示:
<table class="table">
<thead><tr>
<th>Artist Name</th>
<th>Track Title</th>
<th>Version</th>
<th>Track Duration</th>
<th>Recording Year</th>
<th></th>
</tr>
</thead>
<tbody>
<isrcrow></isrcrow>
</tbody>
</table>
指令如下:
(function() {
var isrcorderapp;
isrcorderapp = angular.module("isrcorderapp", []);
isrcorderapp.controller("isrcordercontroller", function($scope, $http) {
return $scope.recordingTypes = [
{
type: 'Single'
}, {
type: 'Album'
}, {
type: 'Live'
}, {
type: 'Concert'
}, {
type: 'Instrumental'
}
];
});
isrcorderapp.directive("isrcrow", function() {
return {
restrict: 'E',
template: '<tr>\
<td><input id="artist" ng-model="name"/></td>\
<td><input id="track"/></td>\
<td><select id="isrctype" ng-model="isrctype" ng-change="setState(state)" ng-options="s.type for s in recordingTypes" class="ng-pristine ng-valid"></select></td>\
<td><input id="duration"/></td>\
<td><input id="year"/></td>\
<td><input type="button" value="Add ISRC" onclick="AddIsrc()" class="btn btn-small btn-success" />\
<input type="button" value="Delete" onclick="RemoveIsrc()" class="btn btn-small btn-danger" />\
</td>\
</tr>',
scope: {
name: '='
},
link: function(scope, element, attr) {}
};
});
}).call(this);
我遇到的问题是 isrcrow 指令没有在表格主体内呈现。它呈现在桌子的外面和上方:
有谁知道导致这种行为的原因是什么?
【问题讨论】:
-
如果您没有选项,我建议将
isrcrow设为属性,而在您的HTML 中使用<tr isrcrow></tr>,这显然意味着修改您的模板代码以排除<tr>s。 -
这个建议奏效了。我怎样才能让这个答案
-
我也有同样的问题。但我的东西在 IE 中有效,在 Chrome 中无效。
标签: angularjs angularjs-directive