javascript - How can I pass variable from one function to another in angularJS? -


$scope.openmodal = function (page, size) {     console.log(page); // working      $uibmodal.open({         animation: true,         templateurl: 'app/pages/servers/newrole.html',         size: size,         resolve: {             items: function () {                 return $scope.items;             }         }      });  };   $scope.hello = function() {      console.log(page); // need value of page above function       var btn = document.createelement("button");      var t = document.createtextnode("abc");       btn.classlist.add("btn-primary", 'btn-xs', 'btn');      btn.appendchild(t);       document.getelementbyid('id1').appendchild(btn);  } 

i have tried using global variable , assigning page saying undefined.

i can access variable calling hello(page) inside openmodal, won't work call hello() when it's not needed.

i have 2 buttons , calling openmodal function on click of 'btn1', , passing page parameter on button , there button inside modal 'btn2', calling hello() on click of btn2.

$scope.openmodal = function (page, size) {     console.log(page); // working     $uibmodal.open({         animation: true,         templateurl: 'app/pages/servers/newrole.html',         controller: modalinstancectrl, //resolved items can use in controller         size: size,         resolve: {             items: function () {                 return page; // return value             }         }      });  };     angular.module('ui.bootstrap.demo').controller('modalinstancectrl', function ($scope, $uibmodalinstance, items) {      $scope.hello = function() {          console.log(items); // here can value        }     }); 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -