我试图从TypeScript和AngularJS开始,但是在基于Tutorial的前几行之后,我得到了这个令人困惑的错误。

我的mydModule似乎有问题吗?

angular.js:68 Uncaught Error: [$injector:modulerr] Failed to instantiate module mydModule due to:Error: [$injector:nomod] Module 'mydModule' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

index.html

<html ng-app="mydModule">
<body>
    <script src="Scripts/angular.js"></script>
    <script src="App_Scripts/start.js"></script>
    <script src="App_Scripts/startController.js"></script>
    <div class="wrapper container">
        <div class="row"  ng-controller="startController as vm">
                <div id="content">
                    Tst:
                    <ul>
                        <li ng-repeat="label in vm.sequence">
                            <span ng-style="{'background-color':label.Color}">{{label.Text}}</span>
                        </li>
                    </ul>
               </div>
       </div>
   </div>
</body>
</html>


start.ts

/// <reference path="../scripts/typings/angularjs/angular.d.ts" />
module DosierradApplication {
    export class StartPage {
        static mydModule = angular.module('startPage', ['ngResource']);
    }
}


startController.ts

/// <reference path="../scripts/typings/angularjs/angular.d.ts" />
/// <reference path="start.ts" />
module DosierradApplication {
    export class startController {
        constructor(private $scope: ng.IScope) {

        }

        sequence = [
            {
                "Id": 0,
                "Text": "all good",
                "Color": "#0f0"
            },
            {
                "Id": 1,
                "Text": "not good",
                "Color": "#ff0"
            }
        ];
    }

    StartPage.mydModule.controller('startController', ["$scope", startController]);
}

最佳答案

您已将模块称为“ startPage”,并尝试以“ mydModule”的身份对其进行访问。
所以应该

<html ng-app="startPage">


mydModule是变量名,而不是上述示例中的模块名。

10-06 05:26