javascript - custom blur not working correctly [AngularJS] -


i trying create notifications this:

http://plnkr.co/edit/gbfiofdnb2oc4zjarqtp?p=preview

but unsuccesful integrade in script, because when click outside notification box nothing happend.

here script:

'use strict'; var app = angular.module('notifications',['ngroute'], function($interpolateprovider) {     $interpolateprovider.startsymbol('<%');     $interpolateprovider.endsymbol('%>');   })         .controller('notificationcontroller', function($scope, $http) {             $http.get("/api/notification")             .success(function (response) {                 $scope.notys = response;             });              $scope.notifications = {                 visible: false               };             $scope.shownotifications = function(flag) {                 $scope.notifications.visible = flag;               };              })            .directive('customblur', function(){             return {               restrict: 'a',               scope: {                 'customblur': '='               },               link: function(scope, element, attr) {                 element.on('click', function(event){                   var targetattr = angular.element(event.target).attr('custom-blur');                   console.log(targetattr);                   if (typeof targetattr !== 'undefined') {                     scope.$apply(function(){                       scope.customblur = false;                     });                   }                  });               }             };           }); 

problem when click outside notifcation box not return shuld return notification.visible if click notification box return undefined expected.

that result for: console.log(targetattr);

i ran code in plunkr , tried fix error. found module name , controller name not same.

uncaught error: [$injector:modulerr] failed instantiate module demo due to: error: [$injector:nomod] module 'demo' not available! either misspelled module name or forgot load it. if registering module ensure specify dependencies second argument. http://errors.angularjs.org/1.4.2/$injector/nomod?p0=demo 

this error says angular not able find module 'demo'. made changes html here. line:

<html ng-app="notifications"> 

after got error:

uncaught error: [$injector:modulerr] failed instantiate module notifications due to: error: [$injector:modulerr] failed instantiate module ngroute due to: error: [$injector:nomod] module 'ngroute' not available! either misspelled module name or forgot load it. if registering module ensure specify dependencies second argument. 

this says ngroute using here angular.module('notifications',['ngroute'], function($interpolateprovider) { not available. removed it. (just fix error.).so did changes js. line:

angular.module('notifications',[], function($interpolateprovider) { 

ok after got error:

error: [ng:areq] argument 'ctrl' not function, got undefined http://errors.angularjs.org/1.4.2/ng/areq?p0=ctrl&p1=not%20a%20function%2c%20got%20undefined 

which says ctrl not defined properly.so made changes html again.this line

 <body ng-controller="notificationcontroller"> 

ok. after fixing found no more error. , plunker started working again. can see plunker here : plunker

hope helps you. thank you.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -