简体   繁体   English

Angular js模块无法加载

[英]angular js module cannot be loaded

I am just starting with AngularJS. 我只是从AngularJS开始。 Just tried hands with a simple snippet (below). 只需尝试用一个简单的代码片段(如下)。 But I am seeing the error in the browser console. 但是我在浏览器控制台中看到错误。

Uncaught Error: [$injector:modulerr] Failed to instantiate module notesApp due to: Error: [$injector:nomod] Module 'notesApp' is not available! 未捕获的错误:[$ injector:modulerr]由于以下原因而无法实例化模块notesApp:错误:[$ injector:nomod]模块'notesApp'不可用! 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. 如果注册模块,请确保将依赖项指定为第二个参数。

<html ng-app="notesApp">
    <body ng-controller="notesMainCtrl as ctrl">
        <form ng-submit="ctrl.submitAction()">
            <input type="text"></input>
            <input type="password"></input>
            <input type="submit"></input>
        </form>
        <span>username:{{ctrl.username}}  password:{{ctrl.password}}</span>

        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.js" />
        <script type="text/javascript">
            angular.module('notesApp',[])
                    .controller('notesMainCtrl',[function(){
                        this.username="username";
                        this.password="password";
                        this.submitAction=function(){
                            console.log(this.username+':::'this.password);
                        };
                    }]);
        </script>
    </body>
</html>

There were a couple of things, here is working plunker.. 有几件事,这里正在工作

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.js" />

this can't be self closing. 这不能自我关闭。 ie needs </script> 即需要</script>

console.log(this.username+':::'this.password);

there is a missing + sign here between ':::' and this.password ':::'this.password之间缺少一个+

--- Edit --- -编辑-

Just some other observations, you are missing ng-model on the input boxes, so they won't two-way data bind any information back to the controller. 只是其他一些观察,您在输入框中缺少ng-model ,因此它们不会two-way数据将任何信息绑定回控制器。

<input type="password" ng-model="password" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM