<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alphaexcel</title>
    <description>The latest articles on DEV Community by Alphaexcel (@alphaexcel).</description>
    <link>https://dev.to/alphaexcel</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F876849%2F1cd8e308-f828-4fc5-a841-7eb3fc136b0c.jpg</url>
      <title>DEV Community: Alphaexcel</title>
      <link>https://dev.to/alphaexcel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alphaexcel"/>
    <language>en</language>
    <item>
      <title>AI Won't Replace Developers, But It Will Change How We Work</title>
      <dc:creator>Alphaexcel</dc:creator>
      <pubDate>Wed, 25 Mar 2026 00:03:52 +0000</pubDate>
      <link>https://dev.to/alphaexcel/ai-wont-replace-developers-but-it-will-change-how-we-work-4apb</link>
      <guid>https://dev.to/alphaexcel/ai-wont-replace-developers-but-it-will-change-how-we-work-4apb</guid>
      <description>&lt;p&gt;Lately, there’s been a growing fear in the software engineering world.&lt;/p&gt;

&lt;p&gt;You see it everywhere:&lt;/p&gt;

&lt;p&gt;developers on forums&lt;/p&gt;

&lt;p&gt;people learning to code&lt;/p&gt;

&lt;p&gt;tech conversations online&lt;/p&gt;

&lt;p&gt;And the questions are usually the same:&lt;/p&gt;

&lt;p&gt;Will AI replace developers?&lt;/p&gt;

&lt;p&gt;Is it still worth learning programming?&lt;/p&gt;

&lt;p&gt;Are we too late to the industry?&lt;/p&gt;

&lt;p&gt;It’s easy to understand why people feel this way.&lt;/p&gt;

&lt;p&gt;AI tools today can:&lt;/p&gt;

&lt;p&gt;generate code&lt;/p&gt;

&lt;p&gt;debug errors&lt;/p&gt;

&lt;p&gt;explain complex concepts&lt;/p&gt;

&lt;p&gt;write documentation&lt;/p&gt;

&lt;p&gt;scaffold entire project structures&lt;/p&gt;

&lt;p&gt;That’s a huge shift.&lt;/p&gt;

&lt;p&gt;And yes, there are moments where you use AI and think:&lt;/p&gt;

&lt;p&gt;“This just did in seconds what would have taken me much longer.”&lt;/p&gt;

&lt;p&gt;That can feel intimidating at first.&lt;/p&gt;

&lt;p&gt;But I’ve started seeing it differently — not as a replacement, but as a tool that changes how we work.&lt;/p&gt;

&lt;p&gt;💡 Code Generation Is Not Software Engineering&lt;/p&gt;

&lt;p&gt;One major misunderstanding in the AI discussion is this:&lt;/p&gt;

&lt;p&gt;People assume that generating code equals software engineering.&lt;/p&gt;

&lt;p&gt;It doesn’t.&lt;/p&gt;

&lt;p&gt;Software engineering involves:&lt;/p&gt;

&lt;p&gt;understanding problems&lt;/p&gt;

&lt;p&gt;designing solutions&lt;/p&gt;

&lt;p&gt;making architectural decisions&lt;/p&gt;

&lt;p&gt;thinking about scalability&lt;/p&gt;

&lt;p&gt;maintaining systems over time&lt;/p&gt;

&lt;p&gt;communicating with teams&lt;/p&gt;

&lt;p&gt;AI can generate output.&lt;/p&gt;

&lt;p&gt;But developers provide judgment.&lt;/p&gt;

&lt;p&gt;And that difference matters.&lt;/p&gt;

&lt;p&gt;⚙️ Where AI Actually Helps Developers&lt;/p&gt;

&lt;p&gt;Instead of replacing developers, AI is becoming a productivity tool.&lt;/p&gt;

&lt;p&gt;Here’s where it helps most:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Development support&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;generating boilerplate code&lt;/p&gt;

&lt;p&gt;scaffolding projects faster&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Learning support&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;explaining unfamiliar concepts&lt;/p&gt;

&lt;p&gt;breaking down complex frameworks&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Debugging support&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;suggesting possible causes of errors&lt;/p&gt;

&lt;p&gt;helping interpret stack traces&lt;/p&gt;

&lt;p&gt;This doesn’t remove developers.&lt;/p&gt;

&lt;p&gt;It removes friction.&lt;/p&gt;

&lt;p&gt;⚠️ The Real Risk Isn’t AI&lt;/p&gt;

&lt;p&gt;The real risk isn’t AI.&lt;/p&gt;

&lt;p&gt;The real risk is refusing to adapt.&lt;/p&gt;

&lt;p&gt;Technology has always evolved:&lt;/p&gt;

&lt;p&gt;new frameworks appear&lt;/p&gt;

&lt;p&gt;tools improve&lt;/p&gt;

&lt;p&gt;workflows change&lt;/p&gt;

&lt;p&gt;AI is just a faster version of that change.&lt;/p&gt;

&lt;p&gt;Developers who learn how to work with AI will likely become more productive.&lt;/p&gt;

&lt;p&gt;Developers who ignore it may struggle to keep up.&lt;/p&gt;

&lt;p&gt;👨‍💻 My Perspective as Someone Growing in Tech&lt;/p&gt;

&lt;p&gt;As someone still growing in tech, I’ve decided not to see AI as competition.&lt;/p&gt;

&lt;p&gt;Instead, I see it as:&lt;/p&gt;

&lt;p&gt;a learning accelerator&lt;/p&gt;

&lt;p&gt;a productivity tool&lt;/p&gt;

&lt;p&gt;and sometimes a debugging partner&lt;/p&gt;

&lt;p&gt;There are moments where I use AI and think:&lt;/p&gt;

&lt;p&gt;“This is doing in seconds what would have taken me much longer.”&lt;/p&gt;

&lt;p&gt;But instead of seeing that as a threat, I see it as a way to grow faster.&lt;/p&gt;

&lt;p&gt;However, there’s an important truth:&lt;/p&gt;

&lt;p&gt;If you rely on AI without understanding the fundamentals, it will eventually show.&lt;/p&gt;

&lt;p&gt;That’s why I’m focusing on:&lt;/p&gt;

&lt;p&gt;core programming concepts&lt;/p&gt;

&lt;p&gt;problem-solving&lt;/p&gt;

&lt;p&gt;system thinking&lt;/p&gt;

&lt;p&gt;and learning how to use AI effectively&lt;/p&gt;

&lt;p&gt;🚀 The Future of Developers&lt;/p&gt;

&lt;p&gt;AI will definitely change software development.&lt;/p&gt;

&lt;p&gt;But it won’t eliminate developers.&lt;/p&gt;

&lt;p&gt;It will change what makes a developer valuable.&lt;/p&gt;

&lt;p&gt;In the future, strong developers will likely need:&lt;/p&gt;

&lt;p&gt;better problem-solving skills&lt;/p&gt;

&lt;p&gt;stronger system understanding&lt;/p&gt;

&lt;p&gt;better judgment&lt;/p&gt;

&lt;p&gt;ability to work with intelligent tools&lt;/p&gt;

&lt;p&gt;And honestly, that’s not something to fear.&lt;/p&gt;

&lt;p&gt;It’s something to grow into.&lt;/p&gt;

&lt;p&gt;🔚 Final Thought&lt;/p&gt;

&lt;p&gt;AI is not the enemy of developers.&lt;/p&gt;

&lt;p&gt;It is a tool.&lt;/p&gt;

&lt;p&gt;And like every powerful tool, what matters is how it is used.&lt;/p&gt;

&lt;p&gt;The developers who thrive will not be the ones who resist change the most, but the ones who learn how to adapt and work with it.&lt;/p&gt;

&lt;p&gt;What’s your take on AI in development?&lt;/p&gt;

&lt;p&gt;Do you see it as a threat, a tool, or something in between?&lt;/p&gt;

</description>
      <category>ai</category>
      <category>softwareengineering</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Automated Diaspora Data Broker for African Exports</title>
      <dc:creator>Alphaexcel</dc:creator>
      <pubDate>Sun, 06 Jul 2025 16:18:28 +0000</pubDate>
      <link>https://dev.to/alphaexcel/automated-diaspora-data-broker-for-african-exports-31c6</link>
      <guid>https://dev.to/alphaexcel/automated-diaspora-data-broker-for-african-exports-31c6</guid>
      <description>&lt;h2&gt;
  
  
  🛠️ What I Built
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Automated Diaspora Data Broker for African Exports&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
An AI-powered data agent using Runner H to uncover weekly product demand insights from diaspora communities across the globe — helping small African exporters make smarter decisions and connect directly with active buyers.&lt;/p&gt;

&lt;p&gt;This AI agent finds trending products, unmet diaspora needs, and untapped export opportunities using public social data, compiles everything into a structured Google Sheet, and gives actionable weekly recommendations.&lt;/p&gt;

&lt;p&gt;Watch the automation in &lt;br&gt;
action:&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://player.vimeo.com/video/1099092303" width="710" height="399"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚙️ How I Used Runner H
&lt;/h2&gt;

&lt;p&gt;I created a multi-step prompt for Runner H that does the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Research diaspora conversations&lt;/strong&gt; on platforms like Reddit, Twitter/X, and Facebook groups using keywords like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;“Buy African food”&lt;/li&gt;
&lt;li&gt;“Where to order shea butter”&lt;/li&gt;
&lt;li&gt;“I miss Ankara fabric in Germany”&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Analyze for patterns&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Top requested African products&lt;/li&gt;
&lt;li&gt;Most mentioned countries and cities&lt;/li&gt;
&lt;li&gt;Challenges in sourcing or buying&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Output a structured Google Sheet&lt;/strong&gt; with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Trending Products&lt;/code&gt; tab&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Market Opportunities&lt;/code&gt; tab&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Weekly Recommendation&lt;/code&gt; tab&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Summarize findings&lt;/strong&gt; in 5 simple bullet points exporters can act on.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The prompt runs weekly and serves as an automated research assistant for African SMEs and solopreneurs.&lt;/p&gt;




&lt;h2&gt;
  
  
  🌍 Use Case &amp;amp; Impact
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Real-World Problem
&lt;/h3&gt;

&lt;p&gt;Small-scale exporters across Africa often struggle to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Identify what diaspora consumers truly want&lt;/li&gt;
&lt;li&gt;Know where to target for demand&lt;/li&gt;
&lt;li&gt;Find time or tools to research effectively&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Who This Helps
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;African entrepreneurs&lt;/strong&gt; shipping local goods (e.g., snacks, fashion, cosmetics)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Diaspora-focused vendors&lt;/strong&gt; selling online from the UK, US, or EU&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Export marketers&lt;/strong&gt; and trade promotion agencies&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How This Helps
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Saves time and money doing market research&lt;/li&gt;
&lt;li&gt;Empowers smarter, data-backed exports&lt;/li&gt;
&lt;li&gt;Opens pathways to new markets and unmet needs&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  ❤️ Social Love
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;I’m participating in the &lt;strong&gt;Community Champion&lt;/strong&gt; prize too!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I’ve shared my project on Twitter/X and LinkedIn — please check it out, engage, and share to help spread the vision for African SME empowerment through AI!&lt;/p&gt;

&lt;p&gt;🔗 [&lt;a href="https://x.com/oyinemi/status/1941894145439649816?t=87TNhIQ_JNnrzWCJbVtLwA&amp;amp;s=19" rel="noopener noreferrer"&gt;https://x.com/oyinemi/status/1941894145439649816?t=87TNhIQ_JNnrzWCJbVtLwA&amp;amp;s=19&lt;/a&gt;]  &lt;/p&gt;




&lt;p&gt;Thanks for reading — I hope this inspires other entrepreneurs to use AI tools like Runner H for real-world impact! 🇳🇬✨&lt;br&gt;&lt;br&gt;
Let’s build smarter, export better, and connect global markets through data + creativity.&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>runnerhchallenge</category>
      <category>ai</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>ANGULAR COMPONENT LIFECYCLE HOOK METHODS YOU SHOULD KNOW</title>
      <dc:creator>Alphaexcel</dc:creator>
      <pubDate>Tue, 18 Oct 2022 15:52:17 +0000</pubDate>
      <link>https://dev.to/alphaexcel/angular-component-lifecycle-hook-methods-you-should-know-5aif</link>
      <guid>https://dev.to/alphaexcel/angular-component-lifecycle-hook-methods-you-should-know-5aif</guid>
      <description>&lt;p&gt;Angular Lifecycle Hooks You Need to Know&lt;/p&gt;

&lt;p&gt;What is “Lifecycle” and “Hook”?&lt;/p&gt;

&lt;p&gt;Before understanding Angular lifecycle hooks, let’s break down the two key terms:&lt;/p&gt;

&lt;p&gt;Lifecycle&lt;/p&gt;

&lt;p&gt;Lifecycle refers to the different stages a component goes through from:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creation&lt;/li&gt;
&lt;li&gt;Rendering&lt;/li&gt;
&lt;li&gt;Updating&lt;/li&gt;
&lt;li&gt;And finally destruction&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can think of it like a living organism:&lt;/p&gt;

&lt;p&gt;«It is “born”, it “grows”, and eventually it “dies”.»&lt;/p&gt;




&lt;p&gt;Hook&lt;/p&gt;

&lt;p&gt;A hook refers to specific points (or checkpoints) in a component’s lifecycle where Angular allows you to run custom logic.&lt;/p&gt;

&lt;p&gt;So in simple terms:&lt;/p&gt;

&lt;p&gt;«Hooks are the “entry points” into different stages of a component’s lifecycle.»&lt;/p&gt;




&lt;p&gt;What is Angular Lifecycle Hook?&lt;/p&gt;

&lt;p&gt;An Angular lifecycle hook is a set of special methods that allow you to tap into different stages of a component’s life.&lt;/p&gt;

&lt;p&gt;A component lifecycle begins when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Angular creates (instantiates) a component class&lt;/li&gt;
&lt;li&gt;Renders the component view and its child views&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It continues with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Change detection (when Angular checks for data updates)&lt;/li&gt;
&lt;li&gt;Updates to the view when data-bound properties change&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally, the lifecycle ends when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Angular destroys the component&lt;/li&gt;
&lt;li&gt;Removes it from the DOM (Document Object Model)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;«NB: Directives can also have lifecycle hooks.»&lt;/p&gt;




&lt;p&gt;List of Angular Lifecycle Hooks&lt;/p&gt;

&lt;p&gt;Angular provides the following lifecycle hooks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ngOnChanges()&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ngOnInit()&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ngDoCheck()&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ngAfterContentInit()&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ngAfterContentChecked()&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ngAfterViewInit()&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ngAfterViewChecked()&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ngOnDestroy()&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Most Important Lifecycle Hooks You Should Know&lt;/p&gt;

&lt;p&gt;Although Angular provides many lifecycle hooks, you will mostly use just a few in real projects.&lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;&lt;code&gt;ngOnChanges()&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This hook is called whenever input-bound properties of a component change.&lt;/p&gt;

&lt;p&gt;When to use it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When you want to respond to changes in input data coming from a parent component.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;2.&lt;code&gt;ngOnInit()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is one of the most commonly used lifecycle hooks.&lt;/p&gt;

&lt;p&gt;It runs once after the component is initialized.&lt;/p&gt;

&lt;p&gt;Typical use cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fetching data from APIs&lt;/li&gt;
&lt;li&gt;Initial setup logic&lt;/li&gt;
&lt;li&gt;Component initialization tasks&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Execution Flow Insight&lt;/p&gt;

&lt;p&gt;When a component is created, Angular follows this order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Class is instantiated&lt;/li&gt;
&lt;li&gt;Constructor is called&lt;/li&gt;
&lt;li&gt;Angular sets input properties
4.&lt;code&gt;"ngOnInit()"&lt;/code&gt; is called&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;code&gt;Constructor&lt;/code&gt; vs &lt;code&gt;ngOnInit&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Constructor: Used for basic class setup and dependency injection&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ngOnInit&lt;/code&gt;: Used for initialization logic that depends on Angular bindings&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Simple Explanation:&lt;/p&gt;

&lt;p&gt;When you create a component:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Angular first creates the class&lt;/li&gt;
&lt;li&gt;Then runs the constructor&lt;/li&gt;
&lt;li&gt;Then sets up input properties&lt;/li&gt;
&lt;li&gt;Finally runs &lt;code&gt;"ngOnInit"&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is why &lt;code&gt;"ngOnInit()"&lt;/code&gt; is called after the constructor.&lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;&lt;code&gt;ngOnDestroy()&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This hook is called just before Angular destroys a component.&lt;/p&gt;

&lt;p&gt;When to use it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cleaning up subscriptions&lt;/li&gt;
&lt;li&gt;Clearing timers&lt;/li&gt;
&lt;li&gt;Preventing memory leaks&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Why &lt;code&gt;ngOnDestroy&lt;/code&gt; is Important&lt;/p&gt;

&lt;p&gt;If you don’t clean up properly, your application may:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Consume unnecessary memory&lt;/li&gt;
&lt;li&gt;Continue running background processes&lt;/li&gt;
&lt;li&gt;Cause performance issues&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;"ngOnDestroy()"&lt;/code&gt; helps prevent this.&lt;/p&gt;




&lt;p&gt;Summary of Lifecycle Flow&lt;/p&gt;

&lt;p&gt;Here is a simplified lifecycle flow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Component is created&lt;/li&gt;
&lt;li&gt;Constructor runs&lt;/li&gt;
&lt;li&gt;Angular initializes inputs&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;"ngOnInit()"&lt;/code&gt; runs&lt;/li&gt;
&lt;li&gt;Component updates (change detection)&lt;/li&gt;
&lt;li&gt;Component is destroyed → &lt;code&gt;"ngOnDestroy()"&lt;/code&gt; runs&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;Angular lifecycle hooks help you control what happens at different stages of a component’s life.&lt;/p&gt;

&lt;p&gt;Although Angular provides many hooks, the most important ones you will use daily are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ngOnInit()&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ngOnChanges()&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ngOnDestroy()&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Understanding these three will already allow you to build better and more efficient Angular applications.&lt;/p&gt;

&lt;p&gt;Keep practicing, and these concepts will become second nature.&lt;/p&gt;

&lt;p&gt;Happy Coding 🚀&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>angular</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to fetch data from the backend for PrimeNg drop down</title>
      <dc:creator>Alphaexcel</dc:creator>
      <pubDate>Sun, 02 Oct 2022 03:31:05 +0000</pubDate>
      <link>https://dev.to/alphaexcel/how-to-fetch-data-from-the-backend-for-primeng-drop-down-29e3</link>
      <guid>https://dev.to/alphaexcel/how-to-fetch-data-from-the-backend-for-primeng-drop-down-29e3</guid>
      <description>&lt;p&gt;When using components in PrimeNG, depending on the framework of your choice—which may be Angular, React, or another framework—you'll often need to fetch data from a backend and display it to users.&lt;/p&gt;

&lt;p&gt;Today, we'll be discussing how to use the PrimeNG Dropdown component to display data fetched from a backend service.&lt;/p&gt;

&lt;p&gt;Getting Started&lt;/p&gt;

&lt;p&gt;The first thing you need to do is visit the PrimeNG documentation:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.primefaces.org/primeng/dropdown" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This link takes you directly to the Dropdown component documentation.&lt;/p&gt;

&lt;p&gt;Next, install PrimeNG and PrimeIcons using the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;npm install primeng --save
npm install primeicons --save
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once they have been installed successfully, you'll be able to import PrimeNG modules into your application.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;AccordionModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;primeng/accordion&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;MenuItem&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;primeng/api&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To use the Dropdown component specifically, import:&lt;/p&gt;

&lt;p&gt;import { DropdownModule } from 'primeng/dropdown';&lt;/p&gt;

&lt;p&gt;Then add it to your module imports.&lt;/p&gt;

&lt;p&gt;A Quick Note on PrimeNG Modules&lt;/p&gt;

&lt;p&gt;If you have worked with UI libraries such as Angular Material, PrimeNG, or similar component libraries, you may have noticed that each component requires its corresponding module to be imported.&lt;/p&gt;

&lt;p&gt;This approach helps improve application performance by ensuring that only the components you need are included in the final build.&lt;/p&gt;

&lt;p&gt;A good practice is to create a shared module where you import and export all the PrimeNG modules you frequently use. This makes your project easier to maintain and reduces repetitive imports across your application.&lt;/p&gt;




&lt;p&gt;Fetching Data from the Backend&lt;/p&gt;

&lt;p&gt;The first step is to create an empty array that will hold the data returned from your backend.&lt;/p&gt;

&lt;p&gt;Next, subscribe to a service that contains the function responsible for fetching the data.&lt;/p&gt;

&lt;p&gt;A typical example looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cityService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getCities&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cities&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the data has been assigned to the array, you can bind it to your PrimeNG Dropdown.&lt;/p&gt;




&lt;p&gt;Creating the Dropdown&lt;/p&gt;

&lt;p&gt;The PrimeNG Dropdown component looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p-dropdown&lt;/span&gt;
    &lt;span class="na"&gt;[options]=&lt;/span&gt;&lt;span class="s"&gt;"cities"&lt;/span&gt;
    &lt;span class="na"&gt;[(ngModel)]=&lt;/span&gt;&lt;span class="s"&gt;"selectedCity"&lt;/span&gt;
    &lt;span class="na"&gt;optionLabel=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/p-dropdown&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's look at what each property does:&lt;/p&gt;

&lt;p&gt;Property| Description&lt;br&gt;
&lt;code&gt;"options"|&lt;/code&gt; Contains the array of data displayed in the dropdown&lt;br&gt;
&lt;code&gt;"ngModel"|&lt;/code&gt; Stores the selected value&lt;br&gt;
&lt;code&gt;"optionLabel"|&lt;/code&gt; Determines which property is displayed to the user&lt;/p&gt;

&lt;p&gt;In this example, "cities" represents the array containing the data returned from the backend.&lt;/p&gt;

&lt;p&gt;To better understand how it works, let's use some mock data.&lt;/p&gt;



&lt;p&gt;Understanding the Data Structure&lt;/p&gt;

&lt;p&gt;The following example comes directly from the PrimeNG documentation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;City&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DropdownDemo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="nl"&gt;cities&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;City&lt;/span&gt;&lt;span class="p"&gt;[];&lt;/span&gt;

    &lt;span class="nl"&gt;selectedCity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;City&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cities&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;New York&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;NY&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Rome&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;RM&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;London&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;LDN&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Istanbul&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;IST&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Paris&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;PRS&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;Here&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cities&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;an&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;objects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each object contains two properties:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name"&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;code"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Dropdown component uses the "optionLabel" property to determine which of these values should be displayed.&lt;/p&gt;




&lt;p&gt;Understanding optionLabel&lt;/p&gt;

&lt;p&gt;Suppose we have the following Dropdown:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p-dropdown&lt;/span&gt;
    &lt;span class="na"&gt;[options]=&lt;/span&gt;&lt;span class="s"&gt;"cities"&lt;/span&gt;
    &lt;span class="na"&gt;[(ngModel)]=&lt;/span&gt;&lt;span class="s"&gt;"selectedCity"&lt;/span&gt;
    &lt;span class="na"&gt;optionLabel=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/p-dropdown&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since "optionLabel" is set to "name", the dropdown will display:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;New York
Rome
London
Istanbul
Paris
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, if we change the component to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p-dropdown&lt;/span&gt;
    &lt;span class="na"&gt;[options]=&lt;/span&gt;&lt;span class="s"&gt;"cities"&lt;/span&gt;
    &lt;span class="na"&gt;[(ngModel)]=&lt;/span&gt;&lt;span class="s"&gt;"selectedCity"&lt;/span&gt;
    &lt;span class="na"&gt;optionLabel=&lt;/span&gt;&lt;span class="s"&gt;"code"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/p-dropdown&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The dropdown will instead display:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NY
RM
LDN
IST
PRS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;PrimeNG simply displays whichever property you specify in the "optionLabel".&lt;/p&gt;




&lt;p&gt;Common Mistakes&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Using the Wrong Property Name&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Suppose your API returns:&lt;br&gt;
&lt;code&gt;&lt;br&gt;
[&lt;br&gt;
  {&lt;br&gt;
    "cityName": "Lagos"&lt;br&gt;
  }&lt;br&gt;
]&lt;br&gt;
&lt;/code&gt;`plaintext&lt;br&gt;
This will not work:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
optionLabel="name"&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;plaintext&lt;/p&gt;

&lt;p&gt;Because the property is called "&lt;code&gt;cityName&lt;/code&gt;", not "&lt;code&gt;name&lt;/code&gt;".&lt;/p&gt;

&lt;p&gt;Instead, use:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
optionLabel="cityName"&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;plaintext&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Forgetting to Subscribe&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This won't work:&lt;br&gt;
&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
this.cities = this.cityService.getCities();&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;typescript&lt;br&gt;
You must subscribe to the Observable:&lt;br&gt;
&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
this.cityService.getCities().subscribe(data =&amp;gt; {&lt;br&gt;
    this.cities = data;&lt;br&gt;
});&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;typescript&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Forgetting FormsModule&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you're using &lt;code&gt;"ngModel"&lt;/code&gt;, make sure you've imported:&lt;br&gt;
&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
import { FormsModule } from '@angular/forms';&lt;/p&gt;

&lt;h2&gt;
  
  
  `&lt;code&gt;&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;Working with a PrimeNG Dropdown becomes much easier once you understand three key concepts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;"options"&lt;/code&gt; supplies the data.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;"optionLabel"&lt;/code&gt; determines what users see.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;"ngModel"&lt;/code&gt; stores the selected value.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whether your data comes from a hardcoded array, a REST API, Firebase, or another backend service, the process remains exactly the same once the data is assigned to the array referenced by "options".&lt;/p&gt;

&lt;p&gt;What was the first PrimeNG component that gave you trouble when you started using the library?&lt;/p&gt;

&lt;p&gt;Let me know in the comments.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>productivity</category>
      <category>beginners</category>
      <category>primeng</category>
    </item>
    <item>
      <title>STARTING OUT WITH ANGULAR</title>
      <dc:creator>Alphaexcel</dc:creator>
      <pubDate>Sun, 25 Sep 2022 23:57:32 +0000</pubDate>
      <link>https://dev.to/alphaexcel/starting-out-with-angular-3cia</link>
      <guid>https://dev.to/alphaexcel/starting-out-with-angular-3cia</guid>
      <description>&lt;p&gt;What is Angular?&lt;/p&gt;

&lt;p&gt;Angular is a TypeScript-based JavaScript framework used for building web applications.&lt;/p&gt;

&lt;p&gt;It is also described as a component-based framework that uses TypeScript, HTML, and CSS to build client-side Single Page Applications (SPAs).&lt;/p&gt;

&lt;p&gt;Angular helps developers build structured, scalable applications by breaking the UI into reusable components.&lt;/p&gt;




&lt;p&gt;Why Angular?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Angular is owned and maintained by Google, which means it receives regular updates and long-term support.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is widely used for building enterprise-level applications.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It allows developers to build applications in a modular way, meaning you can focus on individual features without building everything at once.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Angular supports building Single Page Applications (SPA) where content updates dynamically without full page reloads.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It provides built-in tools for testing, routing, and state management, making development more organized.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Structure of Angular&lt;/p&gt;

&lt;p&gt;Angular applications are built using modules and components.&lt;/p&gt;

&lt;p&gt;Each component usually contains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A TypeScript file (".ts") for logic&lt;/li&gt;
&lt;li&gt;An HTML file for the view (what is displayed in the browser)&lt;/li&gt;
&lt;li&gt;A CSS file for styling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Key Structure Concepts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The TypeScript file handles logic and functionality.&lt;/li&gt;
&lt;li&gt;The HTML template controls what the user sees.&lt;/li&gt;
&lt;li&gt;Angular applications have a root module, which acts as the starting point of the application.&lt;/li&gt;
&lt;li&gt;Different components communicate and work together to build the full application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Standalone Components (Angular 14+)&lt;/p&gt;

&lt;p&gt;With Angular 14 and above, standalone components were introduced.&lt;/p&gt;

&lt;p&gt;These components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Do not need to be declared inside a module&lt;/li&gt;
&lt;li&gt;Can function independently like mini modules&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This makes Angular applications more flexible and modern.&lt;/p&gt;




&lt;p&gt;Main Concepts of Angular&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Components&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A component is the basic building block of an Angular application.&lt;/p&gt;

&lt;p&gt;It controls a part of the user interface. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A Navbar component handles navigation&lt;/li&gt;
&lt;li&gt;A Dashboard component handles the main content&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Creating a component:&lt;/p&gt;

&lt;p&gt;ng generate component componentName&lt;/p&gt;

&lt;p&gt;Replace "componentName" with the name you want.&lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;Component Interaction&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Component interaction is how components communicate with each other.&lt;/p&gt;

&lt;p&gt;Parent → Child communication:&lt;/p&gt;

&lt;p&gt;You use "&lt;code&gt;@Input()&lt;/code&gt;" to pass data from parent to child.&lt;/p&gt;

&lt;p&gt;Child → Parent communication:&lt;/p&gt;

&lt;p&gt;You use "&lt;code&gt;@Output()&lt;/code&gt;" with "&lt;code&gt;EventEmitter&lt;/code&gt;".&lt;/p&gt;

&lt;p&gt;NB:&lt;/p&gt;

&lt;p&gt;Decorators are special functions that tell Angular how a class, property, or method should behave.&lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;Pipes&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Pipes are simple functions used in Angular templates to transform data.&lt;/p&gt;

&lt;p&gt;They take input and return a formatted output.&lt;/p&gt;

&lt;p&gt;Example uses:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dates&lt;/li&gt;
&lt;li&gt;Currency&lt;/li&gt;
&lt;li&gt;Text formatting&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight liquid"&gt;&lt;code&gt;&lt;span class="cp"&gt;{{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'26/01/1997'&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s1"&gt;'dd/MM/yyyy'&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;}}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The "|" symbol is called a pipe operator.&lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;Directives&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Directives are classes that add extra behavior to elements in Angular.&lt;/p&gt;

&lt;p&gt;They help you control:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Structure&lt;/li&gt;
&lt;li&gt;Appearance&lt;/li&gt;
&lt;li&gt;Behavior of elements&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Types of directives:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Component Directives&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These are the components themselves used in templates.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Attribute Directives&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Used to change appearance or behavior of elements.&lt;/p&gt;

&lt;p&gt;Examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ngClass"&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ngStyle"&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ngModel"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Structural Directives&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Used to change the structure of the DOM.&lt;/p&gt;

&lt;p&gt;Examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;*ngIf"&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;*ngFor"&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;*ngSwitch"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;ol&gt;
&lt;li&gt;Routing&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Routing is how you navigate between different pages or views in an Angular application.&lt;/p&gt;

&lt;p&gt;It allows you to move between:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Home page&lt;/li&gt;
&lt;li&gt;Login page&lt;/li&gt;
&lt;li&gt;Dashboard&lt;/li&gt;
&lt;li&gt;Other views&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;How routing works:&lt;/p&gt;

&lt;p&gt;Angular uses a "router-outlet" to display matched components.&lt;/p&gt;

&lt;p&gt;Example route configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="nx"&gt;component&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ComponentName&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;"path" defines the URL&lt;/li&gt;
&lt;li&gt;"component" defines what should be displayed&lt;/li&gt;
&lt;/ul&gt;




&lt;ol&gt;
&lt;li&gt;Services&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Services are used to handle logic and data that should not be inside components.&lt;/p&gt;

&lt;p&gt;They are commonly used for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;API calls&lt;/li&gt;
&lt;li&gt;Data sharing&lt;/li&gt;
&lt;li&gt;Business logic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Real-life example:&lt;/p&gt;

&lt;p&gt;A service is like a data subscription—you use it to access external data without overloading your component.&lt;/p&gt;




&lt;p&gt;Creating a service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ng generate service photos/photos
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Using Dependency Injection:&lt;/p&gt;

&lt;p&gt;To use a service inside a component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;photoService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PhotoService&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is called Dependency Injection, and it allows Angular to provide the service where needed.&lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;Modules&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Modules are containers that organize an Angular application.&lt;/p&gt;

&lt;p&gt;They hold:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Components&lt;/li&gt;
&lt;li&gt;Services&lt;/li&gt;
&lt;li&gt;Pipes&lt;/li&gt;
&lt;li&gt;Other modules&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Creating a module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ng generate module moduleName
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Important Note:&lt;/p&gt;

&lt;p&gt;An Angular application has one root module, and all other modules are connected to it.&lt;/p&gt;




&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;Angular is a powerful framework that helps you build structured and scalable web applications.&lt;/p&gt;

&lt;p&gt;By understanding components, services, routing, directives, and modules, you can start building real-world applications step by step.&lt;/p&gt;

&lt;p&gt;Keep practicing, and things will start to make more sense with time.&lt;/p&gt;

&lt;p&gt;Happy coding 🚀&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>angular</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
