3

I am trying to integrate angular2 in my PHP app. Here are the steps I have performed

  1. Included necessary JS:

../node_modules/angular2/bundles/angular2-polyfills.js ../node_modules/systemjs/dist/system.src.js ../node_modules/typescript/lib/typescript.js ../node_modules/rxjs/bundles/Rx.js ../node_modules/angular2/bundles/angular2.dev.js

  1. Created angular2 component in Typescript:

import {Component} from 'angular2/core'; @Component({ selector: 'hello-world', template: 'My First Angular 2 App' })
export class AppComponent { }

  1. Config:

<script> System.config({ transpiler: 'typescript', typescriptOptions: { emitDecoratorMetadata: true } }); </script>

  1. Bootstrap:

<script> System.import('angular2/platform/browser').then(function(ng){ System.import('js/app.ts').then(function(src) { ng.bootstrap(src.AppComponent); }).then(null, console.error.bind(console)); }); </script>

Output: enter image description here

EDIT:

It seems that there is a conflict with prototype.js and angular 2. See the pluker: http://plnkr.co/edit/XKKpriTPrTX3tXqqz8v2?p=preview

Arvind Bhardwaj
  • 5,231
  • 5
  • 35
  • 49

1 Answers1

3

I got this error a couple of times. According to this: Angular Quickstart

You might be missing a couple of scripts:

<script src="node_modules/es6-shim/es6-shim.min.js"></script>
<script src="node_modules/systemjs/dist/system-polyfills.js"></script>

If using Internet Explorer, you should also remember to include:

<script src="node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>
Rick
  • 345
  • 2
  • 13
  • is there seprate shim file for every browser like IE ? – Pardeep Jain Mar 01 '16 at 16:58
  • 1
    @PardeepJain Not that i'm aware, but you can probably go over the files in that folder to see what's there :) – Rick Mar 01 '16 at 19:15
  • @PardeepJain: No there is not. The reason to have this for IE11 can be found from that files contents. For example the `function.name` does work on all other major browsers but not in IE. [Here's](http://stackoverflow.com/q/6903762) more details. – Roope Hakulinen Mar 21 '16 at 11:42
  • @RoopeHakulinen I actually think this is meant for >IE8, not just IE11. – Rick Mar 22 '16 at 18:38