angularjs - Rails: How do I load my local Angular 2 app inside a view? -


i have angular 2 app built using angular cli generator: https://github.com/edmundmai/angular-2-playing

this generator: https://github.com/angular/angular-cli

i ran ng serve , have page can see when visit http://localhost:4002

my dist/index.html file in angular 2 app looks this:

<!doctype html> <html> <head>   <meta charset="utf-8">   <title>angulartwo</title>   <base href="/">    <script src="/ember-cli-live-reload.js" type="text/javascript"></script>   <meta name="viewport" content="width=device-width, initial-scale=1">   <link rel="icon" type="image/x-icon" href="favicon.ico">   <script src="http://carbon.ec2.crowdtap.com/component_importer.js"></script> </head> <body>   <angular-two-app>loading...</angular-two-app>        <script src="vendor/es6-shim/es6-shim.js"></script><script src="vendor/reflect-metadata/reflect.js"></script><script src="vendor/systemjs/dist/system.src.js"></script><script src="vendor/zone.js/dist/zone.js"></script>     <script>       system.import('system-config.js').then(function () {         system.import('main');       }).catch(console.error.bind(console));     </script>      </body> <script>   window.carbon.importcomponents({ components: ['ct-button', 'ct-button/ct-button-link', 'ct-dialog', 'ct-progress'] }); </script> </html> 

in rails view, trying include these js files:

<script src="http://localhost:4200/vendor/es6-shim/es6-shim.js"></script> <script src="http://localhost:4200/vendor/reflect-metadata/reflect.js"></script> <script src="http://localhost:4200/vendor/systemjs/dist/system.src.js"></script> <script src="http://localhost:4200/vendor/zone.js/dist/zone.js"></script> <script src="http://localhost:4200/system-config.js"></script> <script src="http://localhost:4200/main.js"></script> 

however, it's not working , complaining main.ts:1uncaught referenceerror: require not defined

is there proper way of doing this?

you need change <base href="/"> tag (line 6) in generated

dist/index.html

to <script>document.write('<base href="' + document.location + '" />');</script>


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -