Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角度JS-视图不';调用本地化setLanguage()时,无法绑定_Angularjs - Fatal编程技术网

Angularjs 角度JS-视图不';调用本地化setLanguage()时,无法绑定

Angularjs 角度JS-视图不';调用本地化setLanguage()时,无法绑定,angularjs,Angularjs,我正在将视图(home.html)绑定到我的html(index.html)页面。在页面加载时,路由会正确进行,并且我的视图也会加载。但是,当我单击index.html上的英语或拉丁语链接时,会从localize对象调用setLanguage()方法,并且我的视图消失/不更新。不确定,为什么 这是我的index.html <body ng-controller="AppController"> <H1 data-i18n="_HomeTitle_"></H1

我正在将视图(home.html)绑定到我的html(index.html)页面。在页面加载时,路由会正确进行,并且我的视图也会加载。但是,当我单击index.html上的英语或拉丁语链接时,会从localize对象调用setLanguage()方法,并且我的视图消失/不更新。不确定,为什么

这是我的index.html

<body ng-controller="AppController">
    <H1 data-i18n="_HomeTitle_"></H1>
    <div data-i18n="_Greeting_"></div>
    <div ng-view></div>
    <hr/>
    <a href="#" ng-click="setEnglishLanguage()">English</a> | <a href="#" ng-click="setPigLatinLanguage()">Latin</a>
</body>
AppController.js:

myapp.controller("AppController",function ($scope, localize) {
    $scope.People = [{FirstName:"Jim", LastName:"Lavin", Email:"jlavin@jimlavin.net", Bio:"Creator and Host of Coding Smackdown TV"}];

    $scope.setEnglishLanguage = function() {

        localize.setLanguage('en-US');
        console.log(localize)
    };

    $scope.setPigLatinLanguage = function() {

        localize.setLanguage('es-es');
        console.log(localize)
    };
});

最有可能的原因是,锚点击触发了url更改,而您的路由器对此进行了干扰并试图对其进行路由。尝试阻止单击时的默认行为

ng-click="setEnglishLanguage($event)"


另一个也一样。

是的。我不会尝试这种方法,因为url在链接点击时不会改变。非常感谢。它起作用了!
myapp.controller("AppController",function ($scope, localize) {
    $scope.People = [{FirstName:"Jim", LastName:"Lavin", Email:"jlavin@jimlavin.net", Bio:"Creator and Host of Coding Smackdown TV"}];

    $scope.setEnglishLanguage = function() {

        localize.setLanguage('en-US');
        console.log(localize)
    };

    $scope.setPigLatinLanguage = function() {

        localize.setLanguage('es-es');
        console.log(localize)
    };
});
ng-click="setEnglishLanguage($event)"
   $scope.setEnglishLanguage = function($event) {
        $event.preventDefault(); //prevent default behavior of location update
        localize.setLanguage('en-US');
        console.log(localize)
    };