Übergabe des Objekts an die anglejs-Direktive vom Controller
Ich versuche, mich mit den AngularJS-Richtlinien zu beschäftigen. Ich muss ein vollständiges Objekt von meinem Hauptcontroller an die Direktive übergeben. Siehe den Code unten und 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>
und das Drehbuch:
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, die Bindung funktioniert einwandfrei für mandat.rum und mandat.person.firstname.
Ich versuche jedoch, mandat.person an die Direktive zu übergeben, und es funktioniert nicht. Ich weiß, ich muss etwas falsch machen, die Frage ist was? :)