jquery - AngularJS Trigger Function within another Controller -


what i'm trying achieve:

  1. fetch/trigger message function alertmessage(); within controller.
  2. select specific message displayed using id alertmessage(id:2);.

current problems:

  1. unable fetch or trigger message function alertmessage(); within statsctrl controller.

  2. apart using var messageid = '1'; unable specify message id through alert function e.g alertmessage(id:2);

i'm still learning angularjs, know may need develop factory or service without knowing how becomes tricky!

any , advice helpful!

controller one:

fittingapp.controller('dashboardctrl', ['$scope','$filter','$timeout','notification','$sce','$mddialog', function($scope,$filter,$timeout,notification,$sce,$mddialog) {   // dashboard > username   var username = 'lucy'; // test name   $scope.username = username;    // dashboard > alert messages   alertmessage();   function alertmessage(){     // message id     var messageid = '1';     // messages     var messages = {       "results": [         {'id':'1','icon':'','button':true,'title':'welcome','subtitle':'hi '+username+', welcome virtual fitting room','content': 'here able browse through selection of our dresses<br/>and shortlist them future refrence. find best<br/>dress you, please let know bit yourself'},         {'id':'2','icon':'','button':false,'title':'raiding rails','subtitle':'','content': 'from measurments have supplied, see have triangle body shape.<br/>please wait while 5 best dresses shape.'},         {'id':'3','icon':'','button':false,'title':'my love list','subtitle':'','content': 'any dresses mark &#9829; store<br/> love list can review @ any<br/> point clicking heart icon.'},         {'id':'4','icon':'','button':false,'title':'show me style','subtitle':'','content': 'feel free through rest of our<br/> collection , &#9829; like.'},         {'id':'5','icon':'','button':false,'title':'second optionions','subtitle':'','content': 'it can tough choose, why not ask<br/> ones know best help<br/>by voting favourites.'}       ]     };     // message result     var messageresult = $filter('filter')(messages.results,{id:messageid})[0];     // message html     var message = '<h2>'+messageresult.title+'</h2><h3>'+messageresult.subtitle+'</h3><p>'+messageresult.content+'</p>';     $scope.message = $sce.trustashtml(message);     // show message     $scope.showmessage = {       active: true     };     // hide message     $scope.hidemessage = function(){       $scope.showmessage.active = !$scope.showmessage.active;       // trigger notification       notification();     };     // hide 'continue' button     $scope.hidebutton = {       active: true     };     if(messageresult.button === true){       $scope.hidebutton.active = !$scope.hidebutton.active;     }   }    // dashboard > notifications   function notification(){     // bethan test notification     $timeout(function(){       notification.bethan({         message: 'hi ' +username+ '! you’re not sure do? hover menu in top right , click',         positiony: 'bottom',         positionx: 'left',         delay: 10000,         templateurl: "views/notification.html"       });     }, 3000);     // rhiannon test notification     $timeout(function(){       notification.rhiannon({         message: 'this dress perfect triangle body shape yours!',         positiony: 'bottom',         positionx: 'left',         delay: null,         templateurl: "views/notification.html"       });     }, 6000);   } }]); 

controller two:

fittingapp.controller('statsctrl', ['$scope', function($scope) {   alertmessage(); }]); 

full js

// start app var fittingapp = angular.module('fittingapp');  // dashboard controller fittingapp.controller('dashboardctrl', ['$scope','$filter','$timeout','notification','$sce','$mddialog','customservice', function($scope,$filter,$timeout,notification,$sce,$mddialog,customservice) {      // dashboard > username     var username = 'lucy'; // test name     $scope.username = username;      // dashboard > alert messages     alertmessage();     function alertmessage(){         // message id         var messageid = '1';         // messages         var messages = {             "results": [                 {'id':'1','icon':'','button':true,'title':'welcome','subtitle':'hi '+username+', welcome virtual fitting room','content': 'here able browse through selection of our dresses<br/>and shortlist them future refrence. find best<br/>dress you, please let know bit yourself'},                 {'id':'2','icon':'','button':false,'title':'raiding rails','subtitle':'','content': 'from measurments have supplied, see have triangle body shape.<br/>please wait while 5 best dresses shape.'},                 {'id':'3','icon':'','button':false,'title':'my love list','subtitle':'','content': 'any dresses mark &#9829; store<br/> love list can review @ any<br/> point clicking heart icon.'},                 {'id':'4','icon':'','button':false,'title':'show me style','subtitle':'','content': 'feel free through rest of our<br/> collection , &#9829; like.'},                 {'id':'5','icon':'','button':false,'title':'second optionions','subtitle':'','content': 'it can tough choose, why not ask<br/> ones know best help<br/>by voting favourites.'}             ]         };         // message result         var messageresult = $filter('filter')(messages.results,{id:messageid})[0];         // message html         var message = '<h2>'+messageresult.title+'</h2><h3>'+messageresult.subtitle+'</h3><p>'+messageresult.content+'</p>';         $scope.message = $sce.trustashtml(message);         // show message         $scope.showmessage = {         active: true       };         // hide message         $scope.hidemessage = function(){             $scope.showmessage.active = !$scope.showmessage.active;             // trigger notification             notification();         };         // hide 'continue' button         $scope.hidebutton = {             active: true         };         if(messageresult.button === true){             $scope.hidebutton.active = !$scope.hidebutton.active;         }     }      // dashboard > notifications     function notification(){         // bethan test notification         $timeout(function(){             notification.bethan({                 message: 'hi ' +username+ '! you’re not sure do? hover menu in top right , click',                 positiony: 'bottom',                 positionx: 'left',                 delay: 10000,                 templateurl: "views/notification.html"             });         }, 3000);         // rhiannon test notification         $timeout(function(){             notification.rhiannon({                 message: 'this dress perfect triangle body shape yours!',                 positiony: 'bottom',                 positionx: 'left',                 delay: null,                 templateurl: "views/notification.html"             });         }, 6000);     }      // dashboard > menu (fab speed dial)     menu();     function menu(){         $scope.hidden = false;         // menu items         $scope.items = [             {name:"help",icon:"svg/help.svg",direction:"left",backgroundcolor:"rgb(239, 149, 73)"},             {name:"book",icon:"svg/book.svg",direction:"left",backgroundcolor:"rgb(95, 205, 155)"},             {name:"contact",icon:"svg/contact.svg",direction:"left",backgroundcolor:"rgb(32, 133, 188)"},             {name:"share",icon:"svg/share.svg",direction:"left",backgroundcolor:"rgb(102, 181, 215)"},             {name:"exit",icon:"svg/exit.svg",direction:"left",backgroundcolor:"rgb(255, 206, 97)"}         ];     }      // example     $scope.$watchcollection(function() { return customservice.showmsg; }, function(o, n){         if(n === true){             showmessage("success");         }     });     var showmessage = function(msg){         alert(msg);         customservice.showmsg = false;     };     // end example  }]); // end dashboard controller  // stats controller fittingapp.controller('statsctrl', ['$scope', 'customservice', function($scope, customservice) {      // example     $scope.clickme = function(){         console.log("set true");         customservice.showmsg = true;     };     // end example      // default stats (average uk woman)     defaultstats();     function defaultstats(){         $scope.height = 525; // 5'3"         $scope.chest = 32; // 32"         $scope.waist = 30; // 30"         $scope.hips = 34; // 34"         $scope.thighs = 20; // 20"     }      // reset stats     $scope.resetstats = function(){         defaultstats();     };      // body type formula     bodyshape();     function bodyshape(){         var bust = 32;         var waist = 30;         var hips = 34;       var bustmeasure   = "";         var waistmeasure  = "";         var hipsmeasure   = "";         var small   = "small";         var medium  = "medium";         var large   = "large";         var shapetype = "";         if ( bust <= 36 ) { bustmeasure = small;  }         if ( bust <= 44 ) { bustmeasure = medium; }         if ( bust >= 45 ) { bustmeasure = large;  }         if ( waist <= 34 ) { waistmeasure = small;  }         if ( waist <= 41 ) { waistmeasure = medium; }         if ( waist >= 42 ) { waistmeasure = large;  }         if ( hips <= 39 ) { hipsmeasure = small;  }         if ( hips <= 47 ) { hipsmeasure = medium; }         if ( hips >= 48 ) { hipsmeasure = large;  }       var highestvalue = math.max(bust, waist, hips);       var lowestvalue = math.min(bust, waist, hips);       var difference = highestvalue - lowestvalue;       if ( difference <= 5 ){         shapetype = "rectangle";       }       if (waist - bust > 5 && hips - bust > 5) {           shapetype = "triangle";       }       if (bust - waist > 5 && hips - waist > 5) {           shapetype = "hourglass";       }       if (waist - bust > 5 && waist - hips > 5) {           shapetype = "inverted triangle";       }       if (hips - waist > 5 && hips - bust > 5) {           shapetype = "triangle";       }       if (bust - hips > (hips / 20)) {           shapetype = "inverted triangle";       }       if ((bust - hips <= ( hips / 20)) && (waist > (bust * '.75'))) {           shapetype = "rectangle";       }       if (hips - bust > (bust/20)) {          shapetype = "triangle";       }       if ((waist <= (bust * '.75') && waist <= (hips * '.75'))) {          shapetype = "hourglass";       }         $scope.shapetype = shapetype;     } }]); // end stats controller // end app 

here method call functions of controller controller using factory.

demo

$scope.$watchcollection(function() { return customservice; }, function(o, n){     if(n.showmsg === true){       showmessage("success");     } }); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -