2016-07-02 12 views
1

Ich versuche, ist Angular Controller Diese mit AngularJS ein sehr einfaches Login functiniolity Setup instanziiert, was ich habe:kann nicht

<html> 
    <head> 
    <meta charset="utf-8" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <title>Home Page - My ASP.NET Application</title> 
    <link href="/Content/site.css" rel="stylesheet"/> 

    <script src="/Scripts/angular.js"></script> 

    </head> 
    <body ng-app ="MyApp"> 
    <script src="/Scripts/ng/ngLogin.js"></script> 


    <div id="loginBox" ng-controller="loginCtrl"> 
    <form action="/" id="userLogin"> 
    <label>User id</label> 
    <input type="text" ng-model="userId" /> 
    <label>Password</label> 
    <input type="text" ng-model="password" /> 

    <input type="button" name="loginSubmit" ng-click="submit()" value="Login" /> 
    </form> 
    </div> 

    </body> 
    </html> 

ngLogin.js

angular.module("MyApp").controller('loginCtrl', ['$scope', '$log', function($scope, $log) { 
    alert($scope.userId); 
    $scope.submit = function() { 
     var usrName = $scope.userId; 
     var password = $scope.password; 
     alert(usrName); 
     $log.log(usrName); 
    } 
}]); 

Aber wenn ich die Login-Button nichts klicken passiert weder der Alarm noch irgendetwas im Konsolenprotokoll, was mache ich falsch?

Antwort

1

eine Abhängigkeiten Array übergeben, wenn Sie Ihr Modul registrieren:

angular.module("MyApp", []) 

Error: [$injector:nomod] Module 'MyApp' 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.

+0

Thankyou arbeitete. Ein Mann muss das Abhängigkeits-Array übergeben haben. – Maven

+1

Valar Passulis - alle Männer müssen passieren –