为什么控制器没有绑定到角度app变量

时间:2015-06-19 08:44:47

标签: javascript angularjs

为什么ngController scheduleController没有绑定到页面。但同样适用于this视频(@ 29分钟)

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="">
<head>
    <title></title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
</head>
<body ng-controller="scheduleController">
    <div class="container">
        <select ng-model="test" ng-options="schedule for schedule in scheduler.scheduleType"> 
        </select>
        {{value}}
    </div>

    <script src="Scripts/angular.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
        <script>
            function scheduleController($scope) {
                $scope.scheduler = {
                    scheduleType: ['One time', 'Daily', 'Weekly', 'Monthly'
                        , 'Monthly Relative', 'Yearly', 'Year long']
                };
                $scope.value = 'Shantanu';
            }
    </script>
</body>
</html>

我正在使用AngularJS v1.4.1

1 个答案:

答案 0 :(得分:1)

如果您使用的是Angular 1.3或更高版本,则必须手动将控制器注册到您的应用。这意味着您无法ng-app="",但您需要拥有ng-app="myApp",并拥有:

var myApp = angular.module("myApp", []);

myApp.controller("scheduleController", scheduleController);