-1

how to access angularjs variable from controler to other html page java script

controller
 $scope.names = [
                      {name:'Jani'} ,
              {name:'raaj'} 
                      ];
               $scope.number = names.length;

i need to display use number in html page JavaScript please help in how to use it

2
  • 1
    Please take a few more moments to word your question. Do you want to show it in the view? On another website? In case of the former: docs.angularjs.org/tutorial/step_02 Commented Mar 7, 2016 at 21:46
  • i want to use "number" variable in html page JavaScript code Commented Mar 7, 2016 at 21:52

1 Answer 1

0
function getAngularValue(){
 var number = {};
 number = angular.element(document.getElementById("YOUR_ANGULAR_PAGE_ID")).scope().number;
}
Sign up to request clarification or add additional context in comments.

1 Comment

<html> <script src="ajax.googleapis.com/ajax/libs/angularjs/1.4.8/…> <script > function getAngularValue(){ alert("getAngularValue"); var number = angular.element(document.getElementById("namesCtrl")).scope().names; alert("hi"); } </script> <body> <div ng-app="myApp" ng-controller="namesCtrl"> <p>Looping with objects:</p> {{names }} </ul> <button onclick="getAngularValue()">Click me</button> </div> <script> angular.module('myApp', []).controller('namesCtrl', function($scope) { $scope.names = "test"; }); </script> </body> </html> it is not working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.