6 Replies - 900 Views - Last Post: 23 February 2017 - 11:11 AM

#1 general656  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 286
  • Joined: 25-March 15

AngularJS2/Typescript - Why are my components affected by each other?

Posted 19 February 2017 - 03:16 PM

I have a strange problem. Of course, I can't be sure if the solution will gonna make me look stupid or not. But I fear not, I'm a beginner on Angular2 and Angular/Javascript in general.

I have some components in app.component.ts and this happens. In my HTML code when I remove the one selector, the other selectors get affected too! They all disappear for some reason. Is this a "compilation" problem because it "didn't find the selector" so the whole program exits or what?

For example:

HTML CODE:
<componentA></componentA>
<!--<componentB></componentB>-->



Typescript CODE:
@Component ({selector: 'componentA', 
    template: "Facebook Idiot Bird")}
export class ComponentA {}
@Component ({selector: 'componentB', 
    template: "Floppy Floppity")}
export class ComponentB {}


And because I have the ComponentB tag not in use, neither will work. Is this normal?

This post has been edited by general656: 19 February 2017 - 03:19 PM


Is This A Good Question/Topic? 0
  • +

Replies To: AngularJS2/Typescript - Why are my components affected by each other?

#2 andrewsw  Icon User is offline

  • lashings of ginger beer
  • member icon

Reputation: 6342
  • View blog
  • Posts: 25,594
  • Joined: 12-December 12

Re: AngularJS2/Typescript - Why are my components affected by each other?

Posted 19 February 2017 - 03:48 PM

Moved to Javascript forum.
Was This Post Helpful? 0
  • +
  • -

#3 astonecipher  Icon User is offline

  • Too busy for this
  • member icon

Reputation: 2329
  • View blog
  • Posts: 9,359
  • Joined: 03-December 12

Re: AngularJS2/Typescript - Why are my components affected by each other?

Posted 20 February 2017 - 10:14 AM

app.component.ts should be left alone and you should build off of other components.
Was This Post Helpful? 1
  • +
  • -

#4 general656  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 286
  • Joined: 25-March 15

Re: AngularJS2/Typescript - Why are my components affected by each other?

Posted 22 February 2017 - 09:08 AM

View Postastonecipher, on 20 February 2017 - 10:14 AM, said:

app.component.ts should be left alone and you should build off of other components.


That's not my problem. If you think it is, then explain why please :)/>/> . You shall not give advices to people and don't tell them the "Why". Personally, it frustrates me.

I mean yeah, I should not have the other components in the same file with app.component.ts file, but that's not what I asked, it was in a tutorial and that's why I placed it there.
Personal advice, when you tell people things like that format it to this "If it's not just a tutorial or unnecessary project, then you should have placed the components in a separate file. That's because of <reason>". Then you will look like a gentleman and at the same time a pro, because you explain the reason you say something, and you excuse the purposes of the man you're communicating with.

Sorry for the long story, but these kinds of answers without giving a reason and without being aware of the person they're talking with, just drive me a liiiitle bit crazy.

You don't answer to my problem but your suggestion is helpful.

This post has been edited by general656: 22 February 2017 - 09:41 AM

Was This Post Helpful? 0
  • +
  • -

#5 astonecipher  Icon User is offline

  • Too busy for this
  • member icon

Reputation: 2329
  • View blog
  • Posts: 9,359
  • Joined: 03-December 12

Re: AngularJS2/Typescript - Why are my components affected by each other?

Posted 22 February 2017 - 09:40 AM

Quote

You shall not give advices to people and don't tell them the "Why". Personally, it frustrates me.


I shall do as I please.

If you open the browser console you will see angular errors thrown. In angular 2, a component is designed for a single piece, the app.component.ts runs the app. It is the starting point. Throwing things that don't belong breaks the selector.
Was This Post Helpful? 1
  • +
  • -

#6 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1790
  • View blog
  • Posts: 5,705
  • Joined: 15-January 14

Re: AngularJS2/Typescript - Why are my components affected by each other?

Posted 22 February 2017 - 10:25 AM

Quote

I mean yeah, I should not have the other components in the same file with app.component.ts file, but that's not what I asked, it was in a tutorial and that's why I placed it there.

I would suggest that if you're reading a tutorial that doesn't teach you the correct way to do things, it's probably not a very good tutorial.
Was This Post Helpful? 0
  • +
  • -

#7 general656  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 286
  • Joined: 25-March 15

Re: AngularJS2/Typescript - Why are my components affected by each other?

Posted 23 February 2017 - 11:11 AM

View Postastonecipher, on 22 February 2017 - 09:40 AM, said:

Quote

You shall not give advices to people and don't tell them the "Why". Personally, it frustrates me.


I shall do as I please.

If you open the browser console you will see angular errors thrown. In angular 2, a component is designed for a single piece, the app.component.ts runs the app. It is the starting point. Throwing things that don't belong breaks the selector.


Found the problem in the Browser's Console. It is as I said at first, if it won't find a selector which's mentioned in the component then the whole thing won't work. So you have to make a little bit of Error Handling [I guess] if you want it to work at all situations.

Thank you!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1