我定義了一個Person對象(從後端加載),看起來像這樣正確接收:對象不是由角指令
{
"PersonId":"19894711-2eb9-4edf-92c6-85de2b33d1bb",
"Firstname":"Jacky",
"Lastname":"Chan",
"DateOfBirth":"1963-09-18T00:00:00",
"CreateDate":"2015-12-11T09:15:49.403",
"ModifyDate":"2015-12-11T09:15:49.403"
}
它會顯示正確使用此HTML代碼:
<table>
<tr>
<td>Firstname</td>
<td>
<input type="text" ng-model="person.Firstname" class="form-control"/>
</td>
</tr>
<tr>
<td>Lastname</td>
<td>
<input type="text" ng-model="person.Lastname" class="form-control"/>
</td>
</tr>
</table>
但是,如果我將同一個對象傳遞給指令:
<address-displayer-directive person="person"></address-displayer-directive>
它不起作用。
這是指令的代碼:
myApp.directive("addressDisplayerDirective", [
"addressService",
function (
addressService) {
return {
scope: {
person: "="
},
restrict: "E",
templateUrl: "/Templates/Directives/addressDisplayerDirective.html",
controller: [
"$scope",
function ($scope) {
console.log($scope.person);
$scope.addresses = addressService.GetForPerson($scope.person.Id);
}],
link: function ($scope, $elem, $attrs) {
console.log($attrs.person);
}
};
}]);
即console.log
在鏈路塊,顯示"person"
(字符串,而不是一個對象)。
控制器塊上的console.log
顯示undefined
。
我試着用Plunk模擬它,但它在那裏工作。
任何想法?
這只是你有'人= 「人」 一個錯字'在你的*結束* HTML標籤?如果是這樣,這肯定是錯的 –
是的,複製粘貼錯誤試圖設置我的問題。這不是真的是這樣... – Spikee