0

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

1
  • Can you post your code ? Commented Dec 10, 2015 at 11:59

2 Answers 2

1

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

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

Comments

0

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;

Comments

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.