javascript - Controller 已加载到 DOM 中,但 View 未加载且无法找到 Controller - oclazyload with jade(pugjs)

标签 javascript angularjs node.js pug oclazyload

我正在为我的项目使用 angular 1.6,并使用 angular-ui-routing 为 HTML 模板使用 PugJs 进行路由。 我正在尝试在我的应用程序中实现 Lazyload,但不知何故它不起作用可能是由于 jade。 代码:

var app = angular.module('myApp',['ui.router','oc.lazyLoad']);
app.config(['$ocLazyLoadProvider', function($ocLazyLoadProvider
 {
   $ocLazyLoadProvider.config({
   debug: true,
   modules: [{
   name: 'js',
   files: ['js/*']
 }]
});
}]);

.state("exampleState", {
        url: '/example',
        templateUrl: '/example',
        controller:'exampleCtrl',

        resolve: {
            deps: ['$ocLazyLoad', function($ocLazyLoad) {
                return $ocLazyLoad.load({
                    files: ['/js/exampleCtrl.js']
                })
            }]
        }
    })

Controller :

app.controller('exampleCtrl',function($scope){
  console.log('controller loaded');
});

在前端,我使用 Node 将这些 Jade 转换为 HTML,因此当路由服务访问“templateUrl”时,它将被重定向到此代码:

app.get('/example', function(req, res) {
    res.render('/example');
});

这会在 View 中加载 example.jade。 我在控制台中得到这个

[$controller:ctrlreg] The controller with the name 'exampleCtrl' is not registered.

即使 Controller 文件加载到 DOM 中, View 也不会呈现。欢迎任何有关问题的帮助。谢谢

最佳答案

经过多次搜索和尝试,我找到了解决方案,问题是构建 Controller 时模块的全局变量。而不是使用

app.controller('exampleCtrl',function($scope){
  console.log('controller loaded');
});

我使用了 angular.module('myApp').controller(,,,);

引用:ocLazyLoad Issues

关于javascript - Controller 已加载到 DOM 中,但 View 未加载且无法找到 Controller - oclazyload with jade(pugjs),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44160217/

相关文章:

php - node.js 如何处理故意大的(和坏的)http 请求

node.js - 如何在nodeJS应用程序中通过sequelize ORM存储html值?

javascript - 用于进行一些 meteor 单元测试的最小 Docker 镜像

javascript - 是否可以扩展 EventTarget 接口(interface)?

javascript - javascript中do-while循环的用例?

javascript - 如何在 ui-select 的 ng-model 中使用对象的 id 而不是整个对象

在 PHP echo 上显示 Javascript 提示

javascript - Angular [$interpolate :interr] after $http. 删除

javascript - Angularjs指令单元测试问题

javascript - Mongoose 方法中这个变量的上下文是什么?