2016-03-03 30 views
2

這裏是情況:我正在使用異步。使用systemJS加載腳本(通過腳本,我的意思是jQuery,Angular2,...)。現在我想實現Turbolinks。一切正常,但我的角度組件只是第一次渲染。如果我使用Turbolinks來查看下一頁,我的組件不會呈現。在對象檢查和源代碼中沒有錯誤僅僅是這樣的:Angular2和Turbolinks

<search-app></search-app> 

我在對象檢查疲憊的測試,但是之後第二頁領先,這是唯一的HTML標籤。

這裏有我的網頁上的頭標記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,在那裏我重新INITING所有組件:

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(); 
}); 

Angular 2的版本是beta 7.有誰知道問題在哪裏?非常感謝!

+0

好了,解決了!我需要添加'jQuery(function(){bootstrap(searchApp,[ElementRef,TournamentSearchService]); }); jQuery(document).on('page:load',function(){ bootstrap(searchApp,[ElementRef,TournamentSearchService]); }); '我的angular2應用程序,它的作品。 :-)) –

+0

太棒了,請創建一個答案並接受您自己的答案,以便此問題得到解決。 –

回答

0

我需要把它添加到我的angular2應用程序,它的工作原理:

jQuery(function() { 
    bootstrap(searchApp, [ElementRef, TournamentSearchService]); 
}); 
jQuery(document).on('page:load', function() { 
    bootstrap(searchApp, [ElementRef, TournamentSearchService]); 
});