GVKun编程网logo

angularjs – Angular ui-select error:404(无法加载模板)(angular无法加载路由)

9

在这里,我们将给大家分享关于angularjs–Angularui-selecterror:404(无法加载模板)的知识,让您更了解angular无法加载路由的本质,同时也会涉及到如何更有效地Angu

在这里,我们将给大家分享关于angularjs – Angular ui-select error:404(无法加载模板)的知识,让您更了解angular无法加载路由的本质,同时也会涉及到如何更有效地Angular ui-roter 和AngularJS 通过 ocLazyLoad 实现动态(懒)加载模块和依赖、angularjs – Angular $timeout – TypeError:object不是函数、angularjs – Angular 2中的状态参数(Angular 1&ui-router)的等价物是什么?、angularjs – Angular 2:AOT TypeError:base64不是函数的内容。

本文目录一览:

angularjs – Angular ui-select error:404(无法加载模板)(angular无法加载路由)

angularjs – Angular ui-select error:404(无法加载模板)(angular无法加载路由)

有人使用 angular-ui-select有问题吗?

得到这个错误

GET http://localhost/select2/select.tpl.html 404 (Not Found) angular.js:8539
Error: [$compile:tpload] Failed to load template: select2/select.tpl.html

从文档中 – 我只需要引用select.js和select.css

解决方法

尝试使用/ dist目录中的select.css和select.js文件,而不是/ src目录中的文件.

Angular ui-roter 和AngularJS 通过 ocLazyLoad 实现动态(懒)加载模块和依赖

Angular ui-roter 和AngularJS 通过 ocLazyLoad 实现动态(懒)加载模块和依赖

什么是ui-router

  ui-router是AngularUI库最有用的组件之一(AngularUI库由AngularJS社区构建)。它是一个第三方路由框架,允许通过状态机制组织接口,而不是简单的URL路由。

 什么是ocLoayLoad

  ocLoayLoad是AngularJS的模块按需加载器。按需加载的对象

   简单说就是哪个页面需要什么资源,在加载哪个页面的时候在加载,而不是把所有的资源放在模板里。

 三个主要文件

<script src="angular/1.4.8/angular/angular.min.js"></script>
<script src="angular/ui-router/release/angular-ui-router.min.js"></script>
<script src="angular/oclazyload/src/ocLazyLoad.min.js"></script>

推荐

  1:首先下载插件 可以百度搜索,这里我推荐在线测试的 https://www.bootcdn.cn/angular-ui-router/

  2:github url :https://github.com/366065186/angularjs-oclazyload

    3:Angularjs https://code.angularjs.org/

html文件(部分代码)简单说明

1:首先页面引入上面三个文件

2:在a标签中写入 ui-sref=''链接路径'' 标签

2:在页面定义一块区域用于显示链接内容 <ui-view></ui-view>

 js代码:

首先在module中注入

''ui.router'', ''oc.lazyLoad''然后在通过config进行路由配置。

(function () {
 var app = angular.module("app", [''ui.router'', ''oc.lazyLoad'']) 
 
 // 配置路由
 app.config(function ($stateProvider) {
  $stateProvider
  // 个人中心主页
   .state(''admin/index'', {
    url: ''/admin/index'',
    templateUrl: "/admin/index",
    // 加载页面需要的js
    resolve: load([''/static/js/transfer/adminlte/index.js''])
   })
   // 分类管理列表
   .state(''class/index'', {
    url: ''/class/index'',
    templateUrl: "/class/index",
    resolve: load([
     ''/static/js/transfer/adminlte/classification/index.js''
    ])
   })
   // 轮播图列表
   .state(''roll'', {
    url: ''/roll'',
    templateUrl: "/roll",
    resolve: load([
     ''/static/js/transfer/adminlte/broadcat.js''
    ])
   })
   // 验证码列表
   .state(''code'', {
    url: ''/code'',
    templateUrl: "/code",
    resolve: load([
     ''/static/js/transfer/adminlte/code.js''
    ])
   })
   // 电影列表
   .state(''movie'', {
    url: ''/movie'',
    templateUrl: "/movie",
    resolve: load([
     ''/static/js/transfer/adminlte/movie/movie.js''
    ])
   })
   // 电影编辑
   .state(''movie/edit'', {
    url: ''/movie/edit'',
    templateUrl: "/movie/edit",
    resolve: load([
     ''/static/js/transfer/adminlte/movie/movieedit.js''
    ])
   })
 });

 // 在加载该模块的时候调用$state.go(''admin/index'');,以激活admin/index状态。
 app.run(function ($state) {
  $state.go(''admin/index'');
 });
/*
   * 通过$ocLazyLoad加载页面对应的所需的JS数据
   * 通过$q异步加载JS文件数据其中使用的是promise【保护模式】
  */
function load(srcs, callback) {
 return {
  deps: [
   ''$ocLazyLoad'', ''$q'',
   function ($ocLazyLoad, $q) {
    var deferred = $q.defer();
    var promise = false;
    srcs = angular.isArray(srcs) ? srcs : srcs.split(/\s+/);
    if (!promise) {
     promise = deferred.promise;
    }
    angular.forEach(srcs,
     function (src) {
      promise = promise.then(function () {
       angular.forEach([],
        function (module) {
         if (module.name === src) {
          src = module.module ? module.name : module.files;
         }
        });
       return $ocLazyLoad.load(src);
      });
     });
    deferred.resolve();
    return callback ? promise.then(function () {
     return callback();
    }) : promise;
   }
  ]
 };
}
})();

AngularJS路由设置对象参数规则:

属性 类型 描述
template string   在ng-view中插入简单的html内容
templateUrl string 在ng-view中插入html模版文件
controller string,function / array 在当前模版上执行的controller函数
controllerAs string 为controller指定别名
redirectTo string,function 重定向的地址
resolve object 指定当前controller所依赖的其他模块

 效果图:

总结

以上所述是小编给大家介绍的Angular ui-roter 和AngularJS 通过 ocLazyLoad 实现动态(懒)加载模块和依赖,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

您可能感兴趣的文章:
  • angular之ng-template模板加载
  • 浅谈Angular2 模块懒加载的方法
  • 详解AngularJS通过ocLazyLoad实现动态(懒)加载模块和依赖
  • angularJS+requireJS实现controller及directive的按需加载示例
  • 详解angular2采用自定义指令(Directive)方式加载jquery插件
  • angular+ionic 的app上拉加载更新数据实现方法
  • AngularJS中的按需加载ocLazyLoad示例

angularjs – Angular $timeout – TypeError:object不是函数

angularjs – Angular $timeout – TypeError:object不是函数

我写了一个指令和一个服务.该指令在服务中调用超时函数.但是,一旦达到$timeout,就会抛出一个错误:

TypeError: object is not a function

原始$scope.msg不会显示.并且$timeout函数不等待(20秒)调用回调(或者我假设,因为$scope.msg立即改变).

我完全迷失了.我发现了一些关于超时的问题,但他们似乎都没有这个问题.这个和我一样接近,我已经按照Angularjs directive TypeError: object is not a function的答案了.

这是代码的Plunker:
http://plnkr.co/edit/xrepQOWIHlccbW5atW88?p=preview

这是实际的代码.

angular.module('myApp',[
    'ui.bootstrap','myApp.services','myApp.directives',]);

angular.module('myApp.directives',[]).
directive('logoutNotification',[
    function(admin) {
        return {
            restrict: "E",template: "<div>{{msg}}</div>",controller: ["$scope","$timeout","admin",function($scope,$timeout,admin) {
                    $scope.msg = "hey,no timeout yet";
                    $scope.resetNotification = function() {
                        admin.resetNoticeTimer(function(){
                          $scope.msg = "hey,I'm back from timeout"
                        });
                    };
                }
            ],link: function(scope) {
                scope.resetNotification();
            }
        };
    }
]);

angular.module('myApp.services',[]).
factory('admin',['$rootScope','$location','$timeout',function($rootScope,$location,admin) {
        var noticeTimer;
        return {
            resetNoticeTimer: function(cb) {
                if (noticeTimer) {
                    $timeout.cancel(noticeTimer);
                }
                noticeTimer = $timeout(cb(),20000);
            }
        };
    }
]);

提前致谢!

解决方法

你错误地依赖了依赖项.

你的代码:

factory('admin',admin) {

应该:

factory('admin',$location) {

angularjs – Angular 2中的状态参数(Angular 1&ui-router)的等价物是什么?

angularjs – Angular 2中的状态参数(Angular 1&ui-router)的等价物是什么?

在Angular 1和ui-router中,我使用状态参数来将数据从一个状态传递到另一个状态(不使用URL参数).在Angular 2中有可能吗?

Router,RouteParams,RouterLink和RouteData似乎没有处理这个问题,例如我想将用户对象从一个状态传递到另一个状态

<a ui-sref="home({user: myCtrl.user})">

这在Angular 2中似乎不可能.

解决方法

如果你正在使用Angular 2路由器,你可以通过@RouteParams传递状态,例如,

<a [routerLink]="['/ProductDetail',{id: 1234}]">Product Details</a>

在这种情况下,id是你的状态,它可以是任何对象,例如:

<a [routerLink]="['/ProductDetail',myStateObject]">Product Details</a>

另一方面,Angular 2有一种机制,可以使用绑定传递参数到组件的@input()参数,但这只能在同一路径中使用.

angularjs – Angular 2:AOT TypeError:base64不是函数

angularjs – Angular 2:AOT TypeError:base64不是函数

我试图用aot编译我的项目,但是当我尝试命令时

ngc -p tsconfig-aot.json

它在第一次使用ngFactroy生成aot文件夹,但是当我更改主要ts(如角度文档中提到的)为bootstrap新生成的ngmodulefactory并使用相同命令重新编译项目时
我得到了以下错误

TypeError: base64 is not a function
at Function.from (native)
at Function.from (native)
at Object.extractInlinesourceMap (/Users/apache-tomcat-7.0.61/webapps/ChatAppAngular/node_modules/tsickle/build/src/source_map_utils.js:33:19)
at TsickleCompilerHost.stripAndStoreExistingSourceMap (/Users/apache-tomcat-7.0.61/webapps/ChatAppAngular/node_modules/tsickle/build/src/tsickle_compiler_host.js:128:48)
at TsickleCompilerHost.getSourceFile (/Users/apache-tomcat-7.0.61/webapps/ChatAppAngular/node_modules/tsickle/build/src/tsickle_compiler_host.js:89:25)
at findSourceFile (/Users/apache-tomcat-7.0.61/webapps/ChatAppAngular/node_modules/typescript/lib/typescript.js:63453:29)
at processImportedModules (/Users/apache-tomcat-7.0.61/webapps/ChatAppAngular/node_modules/typescript/lib/typescript.js:63600:25)
at findSourceFile (/Users/apache-tomcat-7.0.61/webapps/ChatAppAngular/node_modules/typescript/lib/typescript.js:63481:17)
at processSourceFile (/Users/apache-tomcat-7.0.61/webapps/ChatAppAngular/node_modules/typescript/lib/typescript.js:63384:27)
at processRootFile (/Users/apache-tomcat-7.0.61/webapps/ChatAppAngular/node_modules/typescript/lib/typescript.js:63271:13)
Compilation Failed

难道我做错了什么 ?

解决方法

我找到答案,它的节点js在这里做问题,AOT需要节点js v6,我只是更新我的节点并发布修复,只是发布我的答案,如果有人面临这个问题.

我们今天的关于angularjs – Angular ui-select error:404(无法加载模板)angular无法加载路由的分享已经告一段落,感谢您的关注,如果您想了解更多关于Angular ui-roter 和AngularJS 通过 ocLazyLoad 实现动态(懒)加载模块和依赖、angularjs – Angular $timeout – TypeError:object不是函数、angularjs – Angular 2中的状态参数(Angular 1&ui-router)的等价物是什么?、angularjs – Angular 2:AOT TypeError:base64不是函数的相关信息,请在本站查询。

本文标签: