I want to create a directive, where it observe the 'playerSearchSpinnerOn' property in the parent scope. where the value changes, than execute code in my directive link function. At the moment, my observe function isn't been triggered when value changes.
html
<div id="addUsers" class="center" spinner spinnerOn="{{playerSearchSpinnerOn}}">
directive
monopolyMenuModule.directive('spinner', function () {
return {
restrict: "A",
link: function (scope, elem, attr) {
attr.observe('spinnerOn', function (newValue, oldValue) {
var spinner = new spinner();
if (newValue) {
// load spinner
spinner.spin(elem);
}
else if (newValue == false) {
// close spinner
spinner(false);
}
});
}
}
parent controller
monopolyMenuModule.controller('AddUsersCtrl', ['$scope', 'addUserServices', 'GameGroupDetails', function ($scope, service, GameGroupDetails) {
// add code to call notifyUsers object.. watch pluralsight "connecting our server to client" and "how signalr works"
$scope.playerSearchSpinnerOn = false;
$scope.FindUsers = function () {
if (GameGroupDetails != null) {
service.FindUsers(GameGroupDetails).done(function () {
// add spinner once group has been show in invite screen
$scope.playerSearchSpinnerOn = true;
});
}
};
}])
when playerSearchSpinnerOn property changes in the AddUserCtrl parent controller, i want my 'spinner' directive to react to this change.
where am i going wrong?
attr.$observethen all code will started working