简体   繁体   中英

how can I get a value from controller{angularJS} to script{js}

I'm working angularJs and in the controller

vm.decodedData

when I display it in the HTML it's works but how can I get it's value to a script 'js' I've been tried a lot of method but all of them gave me undefined like this issue enter link description here

please any advice will be appreciated

You need to get the scope object of any of the elements in the HTML and then you can access the variables there. although it is not advisable to do it, you can get the reference of the body using angular.element and then access the scope object using scope()

angular.module("app", []).controller("ctrl", function($scope){
  $scope.name = "Someone";
});            

    <script>
      $(function(){
        alert("Name from the Angular Scope is '" + angular.element("body").scope().name + "'");
      })
    </script>

Plunker https://run.plnkr.co/UNTAqNTRpIcfRaAv/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM