I'm struggling with this. Rating is a directive from Angular Bootstrap which I don't control, I can define a controller, and I'm trying to serialize the rating through it, however I don't seem to be able to have access to the parent article. I'm new to AngularJS so this is probably the silliest question, but I was experimenting with $scope.$parent
, which in does gives me access to an article
property, but when I do $scope.$parent.article
it returns undefined, there must be another way.
This is the markup in question:
<div class="article full" data-ng-model="article">
<header class="page-header">
<h4>{{article.title}}</h4>
<div class="article-rating" rating ng-controller="RatingsCtrl" value="article.rating" max="5"></div>
</header>
<!-- ... -->
</div>
This is the directive in question https://github.com/angular-ui/bootstrap/blob/master/src/rating/rating.js, and this is my attempt on getting something to work, which doesn't add too much context, but as requested:
angular.module("myApp")
.controller("RatingsCtrl", ($scope) ->
console.log $scope.$parent.article #=> undefined
$scope.$watch 'value', (newVal, oldVal) ->
console.log "newVal = #{newVal} oldVal=#{oldVal}"
console.log $scope.$parent.article #=> undefined
)
I'd need to see the script to reply more precisely, but you said that $scope.parent
has an article
property, but $scope.$parent.article
is undefined.
If that's not a typo, you should use $scope.parent.article
instead...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With