情况如下:我正在使用异步。用systemJS加载脚本(我指的是jQuery,Angular2,.)。现在我想把Turbolinks付诸实施。一切都很好,但我的角度组件只是第一次呈现。如果我使用Turbolinks看到下一页,我的组件就不会呈现。仅在对象检查器和源代码中没有错误:
<search-app></search-app>我已经厌倦了在对象检查器中的测试,但是在第二页引导之后,这只是HTML标记。
下面是我在页面的Head标记中用SystemJS加载脚本:
System.config({
meta: {
'/bundles/frontall': { format: 'global' },
'/bundles/raphael': { format: 'global' },
'/bundles/zopim': { format: 'global' },
'/bundles/angular2': { format: 'global' }
},
packages: {
'angular': {
format: 'register',
defaultExtension: 'js'
},
'angular2': {
format: 'global',
defaultExtension: 'js'
},
'rxjs': {
format: 'global',
defaultExtension: 'js'
}
},
paths: {
'angular2/*': 'scripts/angular2/*',
'rxjs/*': 'scripts/rxjs/*'
}
});
System.import('/bundles/frontall').then(function () {
Promise.all([
System.import('/bundles/zopim'),
System.import('/bundles/raphael'),
System.import('bundles/angular2'),
@RenderSection("asyncScripts", required: false)
]).then(function () {
System.import('angular/searchApp');
});在frontAll包中是文件site.js,其中我重新输入了所有组件:
function componentInit() {
//init material design
$.material.init();
//init texarea autosize
autosize($('textarea'));
//init parallax
$('.parallax-window').parallax();
//init smooth scroll
//SmoothScroll();
//init css3 animate it
$.animateIt();
$.doTimeout();
$.animateItInit();
$.srSmoothscroll({
step: 80,
speed: 90,
ease: 'linear',
target: $('body'),
container: $(window)
});
}
$(function () {
componentInit();
});
$(document).on('page:load', function () {
componentInit();
});角锥2版本是beta 7,有人知道问题出在哪里吗?非常感谢!
发布于 2017-10-06 12:57:04
我需要将这个添加到我的angular2应用程序中,它可以工作:
jQuery(function () {
bootstrap(searchApp, [ElementRef, TournamentSearchService]);
});
jQuery(document).on('page:load', function () {
bootstrap(searchApp, [ElementRef, TournamentSearchService]);
}); https://stackoverflow.com/questions/35780120
复制相似问题