2

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;
1
  • typo scope.points = points; :-P Commented Jan 17, 2015 at 4:37

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

3 Comments

This answer won't work because it wasn't assigned to the window, and is overkill if they know when everything is going to be loaded
i have added the plunker.
@PeterAshwell This is not overkill. The controller is far easier to test when accessing points through a dependency injection. This approach should be encouraged.
0

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;
});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.