predixdesignsystem/px-alert-message

Trigger alert message by event

Closed this issue · 2 comments

For firing an alert message triggered by an event, the component itself does not take a property that replicates behavior like ng-show. Do we have an demo for such kind of implementation for this component ?

Figured out the implementation. The issue was with data binding that was addressed by implementing scope.apply. Here is sample code.

File : AppController.js

// Optional : Might have to inject scope into your controller if $scope is not available
AppController.$inject = ['$scope'];

// Optional : Also might have initialize scope in your constructor 
constructor($scope) {
      this.scope = $scope;
}

// Finally, set error flag on error condition
this.showError = true
this.scope.$apply();

File : view.html
... <px-alert-message ng-show="scope.showError" type="important" message="error message" action='dismiss'> </px-alert-message> ...

That did the trick. Hope that helps.

Great. Thanks for sharing your solution @udyandutta :)