How can I read data (use AngularJS) from other javascript file?

1,670 views
Skip to first unread message

Daniel

unread,
Aug 20, 2012, 7:25:33 AM8/20/12
to ang...@googlegroups.com
I have a very complicated case.

TestData.js(i want to read from this file), TranslationService.js, Translation.js and Translation.xml.

TestData.js

   function TestData() {
       
        var _that = {
             data1 : function(clazz, id, languageId) {
                    var text12 = {name : "textProperty12",
                            displayName : "Example12 same modify-date",
                            type : "text",
                            isEditable : true,
                            isRequired : true,
                            source : this.getSimpleValue("source12", "Max Mustermann", "13.08.2012, 9:00"),
                            target : this.getSimpleValue("target12", "Melanie Musterfrau", "13.08.2012, 9:00"),
                            equals : false,
                            displayNameEnabled : true,
                            context : context,
                            };
                    return [properties = [text12] ];
              }
        };
       
        return _that;
    };


TranslationService.js:

function TranslationService () {
      var _testData = new translation.TestData();      

        var _that = {
               
            getData : function(cid, oid, aid) {
                    return _testData.data1(cid, oid, aid);
                }
        };
        return _that;
    };   

Translation.js:
angular.module("TranslationData", [])
.factory('TranslationService', function($resource){
    return $resource('TranslationService', {});
});


function getTranslationData($scope, TranslationService){
    $scope.todolist = TranslationService.query();
}


Translation.xml:

<?xml version="1.0" encoding="UTF-8"?>

<page xmlns:i18n="http://apache.org/cocoon/i18n/2.1" xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
    <manualScriptControl enabled="true" />
 
    <script type="text/javascript" src="angular-1.0.1.min.js"></script>
     <script type="text/javascript" src="translation/TranslationService.js"></script>
    <script type="text/javascript" src="translation/Translation.js"></script>

   <div ng-app="TranslationData">
                
            <ul ng-controller="getTranslationData">
                <li ng-repeat="test in todolist">{{test.name}}
                </li>
           
            </ul>
</div>
</page>

How can I read data from TestData.js ? Is there a simpler way?

any suggestions?

l...@chemmedia.de

unread,
Aug 22, 2012, 7:32:17 AM8/22/12
to ang...@googlegroups.com, l...@chemmedia.de
Maybe my post was too difficult to understand. So i make it easier.

http://jsfiddle.net/yobing/NXHBW/1/

I need load data1 from TestData.js and save them in $scope.todolist. but how?
Can anyone help me?

Pawel Kozlowski

unread,
Aug 22, 2012, 2:48:21 PM8/22/12
to ang...@googlegroups.com
Hi!
The difficult part of your question is that we don't know much about
the TestData.js file. Is this just a static file sitting on a server?
Or is it generated dynamically? In either case why can't you request
this data with $http?

I was answering a similar question on SO regarding data coming from
"outside" of angular so this might have as well:
http://stackoverflow.com/questions/11994107/how-to-configure-factory-externally-in-angularjs/11994662#11994662

The answer on SO suggest using constants but you could use variables as well.

I hope that this gives some pointers but to help more we would need to
know how your localization data gets generated and how your angular
app is bootstrapped.

Cheers,
Pawel
Reply all
Reply to author
Forward
0 new messages