`AngularJS, controllers and models can't see?
I
I
Igor Gerasimovich2016-05-31 11:02:08
JavaScript
Igor Gerasimovich, 2016-05-31 11:02:08

AngularJS, controllers and models can't see?

i`m need to create multi language Client Side Application, can you help me with my problem.
I have files

index.html

<!DOCTYPE html>
    <html ng-app="app" ng-controller="Language as lang">
    <head>...</head>
    <body>
        <div>{{lang.translation.GameName}}</div>
        <script type="text/javascript" src="/js/less.min.js"></script>
        <script type="text/javascript" src="/js/jquery-2.2.4.min.js"></script>
        <script type="text/javascript" src="/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="/js/main.js"></script>
    </body>
    </html>

services.ang.js

app.service('TranslateSRV', '$scope', '$http', function($scope){
        $scope.translateText = function($scope, $http, language){
            $http.get('../json/language.json').then(function(data){
                return data.data[language];
            });
        };
    });

controllers.ang.js

app.controller('Language', 'TranslateSRV', function(TranslateSRV){
        this.language = 'en';
        this.translation = {};
        this.translate = function() {
            this.translation = TranslateSRV.translateText($scope, $http,this.language);
        };
        this.translate();
    });

language.json

{
      "ua":{
        "GameName":"Правда або дія",
        "ChoseLang":"Оберіть мову гри"
      },
      "ru":{
        "GameName":"Правда или действие",
        "ChoseLang":"Выберите язык игры"
      },
      "en":{
        "GameName":"Truth or Dare",
        "ChoseLang":"Please choose game language"
      }
    }

When I`m run page i see nothing, but i had some errors in my browser console.
Errors

Argument 'Language' is not a function, got string

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kumanin, 2016-05-31
@Mgorunuch

Here is an example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question