我創建的小提琴在下面給出......問題在於,即使在我的dynamicContent指令中的$ compile之後,json對象的模板中的val也沒有被更新。有人可以幫忙嗎?AngularJs:顯示使用指令創建的表內的json對象的數據
var app = angular.module('app', []);
app.controller('fieldController', function ($scope) {
$scope.columns = [
{ label: "First Name", name: "Fname", template: "<div>{{val}}</div>" },
{ label: "Last Name", name: "Lname", template: "<div>{{val}}</div>" },
{ label: "Email", name: "Email", template: "<div>{{val}}</div>" }
];
$scope.data = [
{ Fname: "Tom", Lname: "Assassin", Email: "[email protected]" },
{ Fname: "chris", Lname: "Unkown", Email: "[email protected]" },
{ Fname: "troy", Lname: "forever", Email: "[email protected]" },
{ Fname: "bead", Lname: "trash", Email: "[email protected]" },
];
});
app.directive('dynamicHeader', function ($compile) {
return {
restrict: 'E',
replace: true,
scope: { model : '='},
template: '<div>{{model.label}}</div>',
link: function (scope, element) {
$compile(element)(scope);
}
};
});
app.directive('dynamicContent', function ($compile) {
return {
restrict: 'E',
replace: true,
scope: {
model: '=',
val: '='
},
template: '<div>{{model}}</div>',
link: function (scope, element) {
$compile(element)(scope);
}
};
});
你能請張貼的問題(相關)的代碼。 – PSL
這比其他原文更適用於其他人;只是在這裏使用代碼片段就可以更清楚地知道你的問題是一個指令,標題更改也是有幫助的。 – Claies