Angular注入视图但不绑定

时间:2014-09-03 05:32:37

标签: angularjs

在Index.html我定义:

<html xmlns="http://www.w3.org/1999/xhtml" ng-app="bwp">
<head>
   <title></title>
   <script src="Scripts/angular.min.js"></script>
   <script src="Scripts/angular-route.min.js"></script>
   <script src="js/app.js"></script>
   <script src="app/landingController.js"></script>
</head>
<body>
 <div ng-view></div>
 </body>
</html>

在我定义的app.js中:

var app = angular.module("bwp", ["ngRoute"]);

app.config(function ($routeProvider) {
    $routeProvider.when(
        '/main', {
            templateUrl: 'app/test.html',
            controller: 'testController'
        })
        .otherwise({ redirectTo: '/main' });
});

这是完整的testController.js:

(function() {
   var app = angular.module("bwp");
   var landingController = function ($scope, $http) {
    $scope.test = "this is a test";
};

app.controller("landingController", landingController);

}());

在测试视图中我定义了:

<h1 ng-controller="landingController">
{{test}}
</h1>

当我渲染页面时(通过inspect元素):

<h1 ng-controller="landingController" class="ng-scope ng-binding">
{{test}}
</h1>
  • 请注意,它标识了控制器和范围。

SO ... Angular注入视图但不按预期绑定$ scope.test。我做错了什么?

0 个答案:

没有答案