angularjs - Why is scope variable in directive undefined? -
i have following parent , child (http://jsfiddle.net/j1ee5zss/2/):
<div parent parent-model="my-model"> <div child>child</div> </div>
in child directive trying parent-model, e.g., "my-model":
app.directive("parent", parent); function parent() { var parent = { controller: ["$scope", controller], replace: false, restrict: "a", scope: { model: "=" } }; return parent; function controller($scope) { this.getmodel = function () { return $scope.model; } } } app.directive("child", child); function child() { var child = { link: link, replace: false, require: "^parent", restrict: "a" }; return child; function link(scope, element, attributes, controller) { var model = controller.getmodel(); console.log(model); } }
why model undefined when write console.log(model)?
maybe should observe parentmodel, not model?
scope: { parentmodel: "=" }
or use attribute model.
Comments
Post a Comment