Reputation: 1
I am new to AngularJS I have a variable that consists of objects
var listitems=Model.objectname;
how can I pass (listitems) - controller to useby $scope
I tried to use it on ng-init and access on the controller from $scope
<div ng-app="angularApp" ng-controller="angularController"
ng-init="values=@listitems)">
Thanks
Upvotes: 0
Views: 352
Reputation: 29
Out side variables does not accept in scope, if you want to add variable to $scope
object from outside, you can take reference of the $scope
object like
var scopeItem = angular.element(document.getElementById('controller_id')).scope();
scopeItem.values = Model.objectname;
Upvotes: 0
Reputation: 4310
Everything you put in the $scope
can be used inside any html attributes that start with ng-
or by using {{ }}
brackets.
So for this example,
$scope.listitems = Model.objectname;
Then you can use it in your HTML by {{ listitems }}
anywhere, or if its in ng-init
you want to use it, do something like:
ng-init="getValues(listitems)"
when getValues is your function
Upvotes: 1