Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a Angular controller that have a FormData scope, e.g: $scope.FormData. Data is collected via model connected to a simple form. Also, I have an external non-angular js code on the page. I need to push one of its variables to $scope.FormData.name. How can I do that? Already tried acces it as a global variable via $window, but no luck. Here is the example code:

Angular code:

app.controller('mainController', function ($scope, $http) {

        $scope.formData = {};
        $scope.formData.day = "1";
        $scope.formData.month = "January"; ...

And non-angular code:

var data = [{data1: value1}, {data2:value2}];

Binding this data to a model in a form is not a good option, because this is an object, so, I will get a string in a formData, like [Object, Object].

share|improve this question
    
I think you will need to create a module factory that return this value and inject it in the controller. What exatly the other js file is ? –  Thomas Leduc Sep 30 '14 at 12:05
    
The other file is gmaps.js library. I am trying to push markers object into the scope. –  user3115144 Sep 30 '14 at 12:12
1  
don't separate them, run your maps code from inside a directive –  charlietfl Sep 30 '14 at 13:02
1  
If it's a global var and your gmaps.js is included before angular, you have just to use the var. Like the jsfiddle I created for you : jsfiddle.net/thomasleduc/HB7LU/6847 –  Thomas Leduc Sep 30 '14 at 17:06
    
Thanks, guys! Merging the external code with angular controller did the trick. Question resolved. –  user3115144 Oct 1 '14 at 14:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.