Saravanan
Saravanan

Reputation: 337

how to access template script variable in angularjs

I am having scripts to implement whiteboard using canvas within tags in template page of angularjs. Now i want to assign points[] variable value to angularjs scope variable.

<script>
var points = [];
</script>

how to access this points in angular js controller.

scope.ponts = ponints;

Upvotes: 2

Views: 1149

Answers (2)

Peter Ashwell
Peter Ashwell

Reputation: 4302

You can access it in your controller as it is in the global scope.

See this plunkr:

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

<script>
  var points = [];
</script>

<body ng-controller="MainCtrl">
  <p>Points: {{data}}</p>
</body>

</html>

and app.js

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.data = points;
});

Upvotes: 0

squiroid
squiroid

Reputation: 14037

You can use $window service to get the variable:-

var points = ['1','2'];

var app = angular.module('myapp', []);

app.controller('MainCtrl', ['$scope', '$window', function($scope, $window) {
  $scope.point= $window.points ;
}]);

plunker:- http://plnkr.co/edit/FzybyOZKiLvHuaMaYCuJ?p=preview

Upvotes: 4

Related Questions