Javascript AngularJS变量未解析/显示

Javascript AngularJS变量未解析/显示,javascript,html,angularjs,http,Javascript,Html,Angularjs,Http,以下是相关的HTML: <!DOCTYPE html> <html ng-app="wpApp"> <body> <div ng-controller="controllerMain as main"> <div class="collapse navbar-collapse"> <ul class="nav navbar-nav navbar-left"> <li&g

以下是相关的HTML:

<!DOCTYPE html>
<html ng-app="wpApp">

<body>
<div ng-controller="controllerMain as main">
    <div class="collapse navbar-collapse">
        <ul class="nav navbar-nav navbar-left">
            <li><a href="#">Link 1</a></li>
            <li><a href="#two">Link 2</a></li>
            <li><a href="#three">Link 3</a></li>
        </ul>
    </div>

    <!-- Start of View State -->
    <div class="page-content" style="padding-left:10px; padding-right:10px">
        <div ng-view></div>
    </div>
    <!-- End of View State -->

    <div class="footer">
        <div class="banner">
            {{main.message}}    
        </div>
    </div>
</div>
</body>
</html>
现在,所有设置都与上面一样(其他页面和所有页面都有一些附加控制器),controllerMain的消息会正确地显示在HTML中的指定位置:“这是主控制器”

现在,我需要在controllerMain中进行$http调用,因此我将其更改为:

wpApp.controller("controllerMain", function($http) {
  this.ready = 'true';
  this.message = "This is the Main Controller";
  return $http.get("config.json").success(function(data) {
    console.log("Here");
  });
});
当发生这种情况时,我可以在日志中看到“Here”,但在“{main.message}}”应该显示的地方没有显示任何内容。一点调试告诉我,如果进行$HTTPGET调用,基本上不会显示任何内容。如果我取消通话,将显示消息


这里有什么问题?这与程序的配置方式有关吗?我不了解控制器的工作方式吗?

请尝试删除退货,您不需要从控制器退货

wpApp.controller("controllerMain", function($scope, $http) {
  $scope.ready = 'true';
  $scope.message = "This is the Main Controller";
  $http.get("config.json").success(function(data) {
    console.log("Here");
  });
});
我还建议使用
$scope.message=“这是主控制器”

在html
{{message}}

上删除返回没有任何作用,我想我已经尝试过了。就$scope.message部分而言,我最初尝试过这样做,但它不起作用,因为我的index.html没有关联的控制器。正如您在上面看到的,所有控制器都是使用$routeProvider建立的,我想不出一种方法来添加索引并使其工作。正如我在AngularJS网站上的Plunkr中看到的那样,我是如何使用ng控制器和这个主控制器的。如果你上传JSFIDLE或plunker,你可以添加到你的body标签上。我可以帮助你更多。如果你通过
{main.message}
替换
{message}
而不修改htmlAh,这个应该可以工作。我在脑子里把这两个概念分开。他们一起工作是有道理的。谢谢大家!
wpApp.controller("controllerMain", function($scope, $http) {
  $scope.ready = 'true';
  $scope.message = "This is the Main Controller";
  $http.get("config.json").success(function(data) {
    console.log("Here");
  });
});