加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

具有此名称的控制器未在angularjs ngroute中注册

发布时间:2020-12-17 17:28:07 所属栏目:安全 来源:网络整理
导读:我在mvc- angularjs中创建一个web应用程序,我正在使用ngroute. 我的布局中的Angularjs控制器使用html代码: div class="container body-content" ng-app="MyApp" br / br / br / div style="float:right;" a href="#" class="btn btn-danger"Sign Out/a /div
我在mvc- angularjs中创建一个web应用程序,我正在使用ngroute.

我的布局中的Angularjs控制器使用html代码:

<div class="container body-content" ng-app="MyApp">
    <br />
    <br />
    <br />
    <div style="float:right;">
        <a href="#" class="btn btn-danger">Sign Out</a>
    </div>

    @RenderBody()
    <hr />
</div>

<script>
    (function () {

        var app = angular.module('MyApp',['ngRoute',"ngStorage"]);  

        app.controller('myctrllayout',function ($scope) {  

        });
    })();
 </script>

这是我的欢迎页面:

<div ng-controller="welcome">

</div>
<script>
    angular.module('MyApp',[]) 
    .controller('welcome',function ($scope) { 

    });
</script>

当我运行代码时,我收到以下错误

Error: $controller:ctrlreg A controller with this name is not
registered.

The controller with the name ‘welcome’ is not registered.

当我将我的应用程序从(‘MyApp’,[])更改为(‘MyApp’)时:

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.

解决方法

angular.module可以创建新模块或检索现有模块.这取决于您使用的语法.

这也是官方角度文档上的referenced.

例如

angular.module(‘MyApp’,[])创建一个新模块,因为它包含依赖注入数组(作为第二个参数).

angular.module(‘MyApp’)是现有模块的引用,因为它不包含依赖注入数组.

在您的情况下,它会在第一个代码块上创建一个新模块.所以在第二个代码块中你需要检索它.

如果你改变,问题可能会解决

angular.module(‘MyApp’,[])到第二个代码块中的angular.module(‘MyApp’).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读