I am creating a directive to show success/failure message with slidedown effect depending upon response from http request in controller function.Below is the basic implementation.
<slidemsg msg="rmsg" type="rtype"></slidemsg>
My Directive :
app.directive('slidemsg',function(){
return {restrict : 'EA',
scope:{msg:'=',type:'='},
templateUrl:'views/slideMsg.html',
controller:function($scope){
console.log($scope.msg);
console.log($scope.type);
}}})
Http Request :
app.controller('empController',function($scope,employeeService,$window,$timeout){
$scope.deleteUser=function(id)
{
var deleteUser = $window.confirm('Are you absolutely sure you want to delete?');
if (deleteUser) {
employeeService.deleteEmployee(id).success(function(response){
if(response.success)
{ console.log('Deleted');
$scope.rmsg="Successfully Deleted";
$scope.rtype=true;
}
}
}});
When my page loads first time directive automatically gets called loads template and consoles rmsg & rtype as undefined.But after successful http request when i set rmsg and rtype in success function , directive doesn't get called neither consoles anything written in it.I also tried using $apply but it throws error [$rootScope:inprog]. Am i doing it the right way ?