Here is the structure of my HTML view:
School.html
<html>
<body>
<div class="col-xs-9">
<!-- major bootstrap html code goes over here -->
</div>
<div class="col-xs-3">
<!--Call to directive goes here-->
<div student-profile ngInit="studentId=profileId"></div>
</div>
</body>
</html>
Controllers: SchoolController.js
(function() {
var app = angular.module("SchoolApp")
var SchoolController = function ($scope,$rootScope,...)
{
$scope.profileId = myData.profileId;
}
studentprofileController.js
(function() {
var app = angular
.module("SchoolApp")
.directive('studentProfile',studentProfileDirective)
function studentProfileDirective(){
return {
restrict :'AE',
replace:'true',
controller:studentProfileController,
bindtocontroller:true,
template:'student-profile.html'
}
studentProfileController.inject=['$scope','$rootScope',...];
function studentProfileController($scope,$rootScope,....)
{
var ProfileID = $scope.$parent.profileId;
console.log("ProfileID",ProfileID);
}
};
Currently, I am facing an issue where I am trying to access `$scope.$parent.profileId` in the child directive but it returns "undefined". How can I ensure that the parent controller's scope item `profileId` is available in the child directive?
It seems like the profileId gets assigned in the body controller after the directive has loaded for the first time. How can I handle this synchronization issue in such a scenario?