AngularJS ディレクティブに頭を悩ませようとしています。メインコントローラーからディレクティブに完全なオブジェクトを渡す必要があります。以下のコードと jsfiddle を参照してください: http://jsfiddle.net/graphicsxp/Z5MBf/4/
<body ng-app="myApp">
<div ng-controller="MandatCtrl">
<div person myPerson="mandat.person"></div>
<span>{{mandat.rum}}</span>
<span>{{mandat.person.firstname}}</span>
</div>
そしてスクリプト:
var myApp = angular.module("myApp", []);
myApp.controller("MandatCtrl", function ($scope) {
$scope.mandat = { rum: "15000", person: { id: 1408, firstname: "sam" } };
});
myApp.directive("person", function () {
return {
scope: {
myPerson: "="
},
template: 'test: <div ng-model="myPerson"><input type="text" ng-model="firstname" /></div>'
}
});
OK、mandat.rum と mandat.person.firstname のバインドは正常に機能しています。
ただし、 mandat.person をディレクティブに渡そうとしていますが、機能しません。私は何か間違ったことをしているに違いないことを知っています。問題は何ですか? :)