Making Plunker code run locally on computer

I have put together a Plunker and downloaded it but cannot get it to run locally on my computer.

It's based on an Angular Plunker.

Here is the link:

Click Here to go to Plunker

Can anyone here with setting this up to run locally?
LVL 1
error2013Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
open the files in the editor copy the data to a local location and then run
i.e.
http://plnkr.co/edit/44L6iW?p=info 
save html as index.html
save css as style.css in same directory
save .js as script.js in same directory
open index.html

run in plunker
run in plunker
run locallylocally
0
error2013Author Commented:
Hi there,

The example about is AngularJs which runs Javascript files. I need Angular (Angular 2+) which runs .ts files on source.

AngularJs and Angular are 2 complete different frameworks which are only similar by name.

Thanks
0
Julian HansenCommented:
Before we go into trying to make the plunker work locally why are you not using Angular CLI?

(Requires Node.js is installed)
npm install -g @angular/cli
ng new yourproject
cd yourproject
ng serve

Open in new window

Browse to http://localhost/4200 and your boilerplate is up and running

Download a copy of MS Code
Change to project folder
code .

Open in new window


To add a component
From the project folder

ng g component ComponentName

Open in new window


Angular CLI does all the heavy lifting for you - no real reason not to use it.
0
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

error2013Author Commented:
I've tried that already and I can't get this code to run in it:

app.component.ts:

import { Compiler,Component, ViewContainerRef, ViewChild} from '@angular/core';
import 'rxjs/add/observable/fromPromise';
import { Observable } from 'rxjs/Observable';


@Component({
  selector: 'my-app',
  template: `
    <div>
      <h2>Dynamicaly Add Elements</h2>
      <button (click)="addItem()">add Component</button>
      <div #placeholder></div>
    </div>
  `,
  providers: []
})
export class AppComponent { 
  
  @ViewChild('placeholder', {read: ViewContainerRef}) viewContainerRef;
  private componentFactory: any;
  
  constructor(public compiler:Compiler) {
    const url = 'https://raw.githubusercontent.com/born2net/ng2Boilerplate/master/src/comps/app2/notes/LoadMeComp.ts';
    const importer = url => Observable.fromPromise(System.import(url));
    importer(url).subscribe((component) => {
      this.componentFactory = this.compiler.compileComponentSync(component['LoadMeComp']);
    });
    
  }
  
  addItem () {
    this.viewContainerRef.createComponent(this.componentFactory, 0);
  }
}

Open in new window


That works on a Plunker but not in a CLI project
0
Julian HansenCommented:
The problem is the plunker uses System and CLI uses Webpack so the System.import is going to fail.

The compiler component has been replaced by ComponentFactoryResolver

So your constructor should look like this

constructor(public compiler:ComponentFactoryResolver) {

Open in new window


And your assignment should look like this

this.componentFactory = this.compiler.resolveComponentFactory(component['LoadMeComp']);

Open in new window


The only hurdle would then be this line

const importer = url => Observable.fromPromise(System.import(url));

Open in new window


Which won't work because CLI uses Webpack

SystemJS might be able to do it but I have not tested. You might need to search for how to dynamically import a remote script with CLI as I have not solved that bit yet.
0
error2013Author Commented:
I've tried to change it but it's not liking it:

See Here
0
Julian HansenCommented:
You are still using Compiler instead of ComponentFactoryResolver
0
Julian HansenCommented:
You want more along the lines of below. Also note you are loading a .ts file - which means you have to transpile the file after downloading. Either you need to load a transpiler into your code and do it there (not advisable) or transpile it to js first and then point at the .js file.

@Component({
  selector: 'my-app',
  template: `
    <div>
      <h2>Dynamically Add Elements</h2>
      <button (click)="addItem()">add Component</button>
      <div #placeholder></div>
    </div>
  `,
  providers: []
})
export class AppComponent { 
  
  @ViewChild('placeholder', {read: ViewContainerRef}) viewContainerRef;
  private componentF:any;
  
  constructor(public compiler:ComponentFactoryResolver) {
    const url = 'https://raw.githubusercontent.com/born2net/ng2Boilerplate/master/src/comps/app2/notes/LoadMeComp.ts';
    const importer = url => Observable.fromPromise(import(url));
    importer(url).subscribe((component) => {
      this.componentF = this.compiler.resolveComponentFactory(component['LoadMeComp']);


    });

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
error2013Author Commented:
I've changed it...see here
0
error2013Author Commented:
No error's now but not import either
0
Julian HansenCommented:
Did you read my post about transpiling? Why are you trying to import a component in .ts? Doesn't make sense to me - rather transpile it to js first and then try.
0
error2013Author Commented:
I'm opened to suggestions as long as I can import a component that's available separate to the project. Shall I open a new question for the transpiler issue?
0
Julian HansenCommented:
As I stated in my earlier post - transpile your remote component to a .js file and then import that.
0
error2013Author Commented:
Thanks a million!
0
Julian HansenCommented:
You are welcome.
0
error2013Author Commented:
ps: I've opened a question about the Transpiling :)  .... If the component code is already in .js , is it then possible to get it working? That's would solve the problem for me
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Angular

From novice to tech pro — start learning today.