在这里,我们将给大家分享关于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无法加载路由)
- 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无法加载路由)
得到这个错误
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
解决方法
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不是函数
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)的等价物是什么?
Router,RouteParams,RouterLink和RouteData似乎没有处理这个问题,例如我想将用户对象从一个状态传递到另一个状态
<a ui-sref="home({user: myCtrl.user})">
这在Angular 2中似乎不可能.
解决方法
<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不是函数
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
难道我做错了什么 ?
解决方法
我们今天的关于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不是函数的相关信息,请在本站查询。
本文标签: