控制器在DOM中加载,但视图未加载,无法找到带有jade(pugjs)的controller-oclazyload [英] Controller is loaded in DOM but the view not loaded and can't find controller- oclazyload with jade(pugjs)

查看:150
本文介绍了控制器在DOM中加载,但视图未加载,无法找到带有jade(pugjs)的controller-oclazyload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using angular 1.6 for my project and angular-ui-routing for routing with PugJs for HTML templates. I am trying to implement Lazyload in my application, but somehow its not working may be due to jade. code :

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']
                })
            }]
        }
    })

控制器:

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

在前端我使用节点转换这些玉入HTML,所以当路由访问'templateUrl'时服务将重定向到此代码:

and on the frontend I am using node to convert these jade into HTML, so when 'templateUrl' is accessed by routing services it would be redirected to this code:

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

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

this loads the example.jade in view. I am getting this in console


[$ controller:ctrlreg]名称为exampleCtrl的控制器未注册。

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

即使在DOM中加载控制器文件并且视图未呈现之后。欢迎任何有关问题的帮助。谢谢

Even after controller file is loaded in DOM and also view is not rendering. any help regarding issue welcomed. Thank you

推荐答案

经过太多搜索并尝试找到解决方案,问题是构造控制器时模块的全局变量。而不是使用

After too much search and try i have found the solution, the problem was global variable for the module when constructing controller. Instead of using

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

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

参考: ocLazyLoad问题

这篇关于控制器在DOM中加载,但视图未加载,无法找到带有jade(pugjs)的controller-oclazyload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆