2

I have a list of values in $scope from a controller. Need to access those in a non-angular javascript function.

I have a route like:

.when("/display", {
            templateUrl: "html/display.html",
            controller: "DisplayController"
        }) 

In display.html, I have the following javascript function. I have number of them, in fact

<script>
  var g = new JustGage({
    id: "gauge",
    value: 67,
    min: 0,
    max: 100,
    title: "Visitors"
  });
</script>

In above function, value need to be passed from a list variable in $scope from angular DisplayController.

How do I do it? How do I specify the values which are in $scope.list?

I have seen other questions in similar lines.. Proposed solution are like doing something like

angular.element(myDomElement).scope()

I am using ng-view and not actually specifying any controller in any of the elements. In this case, is it ng-view element?

Any help is appreciated.

3
  • did you try var v=angular.element("#id").scope() , then i think you can use list as v.list inside your javascript function Commented Jun 7, 2015 at 6:11
  • #id.. Not clear which id to be considered. I am using ng-view and route binds html and controller. Commented Jun 7, 2015 at 16:26
  • Can you please create jsfiddle for above question. Commented Jun 7, 2015 at 16:29

1 Answer 1

2

Why not just instantiate JustGage in your controller and add it to the scope?

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

6 Comments

Or be even more Angularly and wrap it in a directive.
Or what Andy said. You should always think directives or filters in most cases.
Good question, but it should have been a comment. It is not answering the asked question
Sometimes, a question can be an answer. In this case a prompt I'll admit.
This gauge expects a div element of id ( for example in the sample code, id: "gauge") to exist already on html page. If I am having a list of gauges to be created dynamically on a page, how do I make sure that div elements with those ids already exist? First the div elements be created and then gauges.
|

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.