<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Chirath Perera on Medium]]></title>
        <description><![CDATA[Stories by Chirath Perera on Medium]]></description>
        <link>https://medium.com/@chirathpereraz1st?source=rss-20023d52af3c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*o5f3U0V46lzyA7mOBLZ9GQ.jpeg</url>
            <title>Stories by Chirath Perera on Medium</title>
            <link>https://medium.com/@chirathpereraz1st?source=rss-20023d52af3c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 18:15:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chirathpereraz1st/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[From Figma to Code - Using MCP Servers and Agentic AI for UI/UX Development]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://levelup.gitconnected.com/from-figma-to-code-using-mcp-servers-and-agentic-ai-for-ui-ux-development-93bed05ee558?source=rss-20023d52af3c------2"><img src="https://cdn-images-1.medium.com/max/1536/1*TjnnrpeKmUqCiKpPH4P0gA.png" width="1536"></a></p><p class="medium-feed-snippet">Modern frontend development used to be heavily manual. Before AI entered the workflow, converting UI/UX designs into working code meant&#x2026;</p><p class="medium-feed-link"><a href="https://levelup.gitconnected.com/from-figma-to-code-using-mcp-servers-and-agentic-ai-for-ui-ux-development-93bed05ee558?source=rss-20023d52af3c------2">Continue reading on Level Up Coding »</a></p></div>]]></description>
            <link>https://levelup.gitconnected.com/from-figma-to-code-using-mcp-servers-and-agentic-ai-for-ui-ux-development-93bed05ee558?source=rss-20023d52af3c------2</link>
            <guid isPermaLink="false">https://medium.com/p/93bed05ee558</guid>
            <dc:creator><![CDATA[Chirath Perera]]></dc:creator>
            <pubDate>Thu, 18 Dec 2025 06:48:54 GMT</pubDate>
            <atom:updated>2025-12-19T03:21:50.926Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Mentoring University Students: Lessons, Challenges, and Rewards from Real Experience]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://chirathpereraz1st.medium.com/mentoring-university-students-lessons-challenges-and-rewards-from-real-experience-90dbbf0a108e?source=rss-20023d52af3c------2"><img src="https://cdn-images-1.medium.com/max/1536/1*U_upytiFldh20LPOWnGuyQ.png" width="1536"></a></p><p class="medium-feed-snippet">Mentorship is often described as a way to guide others, but in my experience, it has been just as much about learning myself. Through&#x2026;</p><p class="medium-feed-link"><a href="https://chirathpereraz1st.medium.com/mentoring-university-students-lessons-challenges-and-rewards-from-real-experience-90dbbf0a108e?source=rss-20023d52af3c------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://chirathpereraz1st.medium.com/mentoring-university-students-lessons-challenges-and-rewards-from-real-experience-90dbbf0a108e?source=rss-20023d52af3c------2</link>
            <guid isPermaLink="false">https://medium.com/p/90dbbf0a108e</guid>
            <dc:creator><![CDATA[Chirath Perera]]></dc:creator>
            <pubDate>Tue, 16 Dec 2025 04:40:48 GMT</pubDate>
            <atom:updated>2025-12-16T04:40:48.660Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Integration HUAWEI HMS Core to current android application and handle Huawei health fitness data]]></title>
            <link>https://levelup.gitconnected.com/integration-huawei-hms-core-to-current-android-application-and-handle-huawei-health-fitness-data-26512f354d1?source=rss-20023d52af3c------2</link>
            <guid isPermaLink="false">https://medium.com/p/26512f354d1</guid>
            <category><![CDATA[huawei]]></category>
            <category><![CDATA[huawei-hms-core]]></category>
            <category><![CDATA[hms-core]]></category>
            <category><![CDATA[huawei-health-kit]]></category>
            <category><![CDATA[healthkit]]></category>
            <dc:creator><![CDATA[Chirath Perera]]></dc:creator>
            <pubDate>Sat, 28 Nov 2020 04:55:13 GMT</pubDate>
            <atom:updated>2020-11-28T04:55:13.421Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I explain how to integrate HUAWEI HMS Core into both existing android application and new android application. Huawei continue the open source core android operating system on its devices. You can add HUAWEI HMS Core to existing android application or a new android application.</p><p>Huawei health kit provides data such as google fitness data. It render open fitness and health data for developers, offering data aggregation, storage, and sharing capabilities for fitness and health apps and devices. It provides open APIs to read and write data and provides a sharing mechanism for consumers to authorize and revoke authorization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ckFDiwcAsyBJF85VN7CbOA.png" /></figure><p>Cloud API</p><p>Open capabilities on the cloud side support both web apps and phone apps. Developers can use RESTful APIs to access the Health Kit data platform. The app can read and write users’ fitness and health data upon the data-type-specific user authorization.</p><ol><li>You have to create an application in Huawei console area. <a href="https://developer.huawei.com/consumer/en/service/josp/agc/index.html">https://developer.huawei.com/consumer/en/console.</a></li><li>Download <strong>agconnect-services.json</strong> file. Go to Project setting &gt; General manager in console.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vger6CcirDyRSOwtVA8DqA.png" /></figure><p>3. Add downloaded agconnect-services file into app’s root directory in your code base.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*9jTy2NODrS6vw426Wsy_JQ.png" /></figure><p>4. Add below maven dependency to project level build.gradle.</p><pre>maven <strong>{ </strong>url <strong>&#39;https://developer.huawei.com/repo/&#39; }</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*c6jBbuaytu5pkKzq2Hxiug.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*kWBFfYJmgjQ6J414J_9WjA.png" /></figure><p>5. Add below dependencies to app level build.gradle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*nXRdyYi_hGdvw4p_j3zf_g.png" /></figure><pre>apply <strong>plugin</strong>: <strong>&#39;com.huawei.agconnect&#39;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*lOWBMAGDWYvQrXy4Cc8BZQ.png" /></figure><pre>maven <strong>{ </strong>url <strong>&#39;https://developer.huawei.com/repo/&#39; }</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*ejUHL7MemnZSaCkisqOOOg.png" /></figure><pre>buildscript <strong>{<br>    </strong>repositories <strong>{</strong><br><em>        </em>maven <strong>{ </strong>url <strong>&#39;https://developer.huawei.com/repo/&#39; }<br>    }<br>    </strong>dependencies <strong>{<br>        </strong>classpath <strong>&#39;com.huawei.agconnect:agcp:1.4.1.300&#39;<br>    }<br>}</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*tWyJrsqg8u1B25i2p15J5g.png" /></figure><pre>implementation <strong>&#39;com.huawei.agconnect:agconnect-core:1.4.1.300&#39;<br></strong>implementation <strong>&quot;com.huawei.hms:health:5.0.4.300&quot;</strong></pre><p>6. Add meta tag into your manifest file.</p><pre>&lt;<strong>meta-data<br>    android:name=&quot;com.huawei.hms.client.appid&quot;<br>    android:value=&quot;your-app-id&quot; </strong>/&gt;</pre><p>you can get the app id from your Huawei console area.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*DnPo4Rr02Y60wrryrv5OYQ.png" /></figure><p>7. Check your device has availability of google services.</p><p>If you are going to integrate Huawei HMS to current android project then You have to check whether google services are available or not in your device. If not you don&#39;t have to check this.</p><pre><strong>int </strong>resultCode =  GooglePlayServicesUtil.<em>isGooglePlayServicesAvailable</em>(<strong>this</strong>.<strong>currentContext</strong>);<br><strong>if </strong>(resultCode == ConnectionResult.<strong><em>SUCCESS</em></strong>) {<br>    <strong>add google services code here</strong><br>} <strong>else {<br>add Huawei code here<br>}</strong>;</pre><p>8. Adding Huawei Init and Huawei SignIn services</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/226cddc664410003a78dd9ebbf199159/href">https://medium.com/media/226cddc664410003a78dd9ebbf199159/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f39538edb33f6eeb017e0ef955eb9243/href">https://medium.com/media/f39538edb33f6eeb017e0ef955eb9243/href</a></iframe><p>9.Getting steps from Huawei Health</p><pre><strong>private class </strong>GetSteps <strong>extends </strong>AsyncTask&lt;Void, Void, Void&gt; {<br>        @Override<br>        <strong>protected </strong>Void doInBackground(Void... arg0) {<br><br>            String ste = <strong>&quot;0&quot;</strong>;<br><br>            HuaweiServices huaweiServices = <strong>new </strong>HuaweiServices(getActivity());<br>            <strong>if </strong>(huaweiServices.isGooglePlayServicesAvailable()) {<br>                DataReadRequest readRequest = <em>queryFitnessData</em>(0);<br>                DataReadResult dataReadResult = Fitness.<strong><em>HistoryApi</em></strong>.readData(<strong>mApiClient</strong>, readRequest).await(1, TimeUnit.<strong><em>MINUTES</em></strong>);<br>                ste = <em>printData</em>(dataReadResult);<br>                sendLatestStepsToServer(ste);<br>            } <strong>else </strong>{<br>                HiHealthOptions hiHealthOptions = HiHealthOptions.<em>builder</em>()<br>                        .addDataType(com.huawei.hms.hihealth.data.DataType.<strong><em>DT_INSTANTANEOUS_HEIGHT</em></strong>, HiHealthOptions.<strong><em>ACCESS_READ</em></strong>)<br>                        .addDataType(com.huawei.hms.hihealth.data.DataType.<strong><em>DT_INSTANTANEOUS_HEIGHT</em></strong>, HiHealthOptions.<strong><em>ACCESS_WRITE</em></strong>)<br>                        .addDataType(com.huawei.hms.hihealth.data.DataType.<strong><em>DT_CONTINUOUS_STEPS_DELTA</em></strong>, HiHealthOptions.<strong><em>ACCESS_READ</em></strong>)<br>                        .addDataType(com.huawei.hms.hihealth.data.DataType.<strong><em>DT_CONTINUOUS_STEPS_DELTA</em></strong>, HiHealthOptions.<strong><em>ACCESS_WRITE</em></strong>)<br>                        .build();<br>                AuthHuaweiId signInHuaweiId = HuaweiIdAuthManager.<em>getExtendedAuthResult</em>(hiHealthOptions);<br><br>                DataController dataController = HuaweiHiHealth.<em>getDataController</em>(getActivity(), signInHuaweiId);<br><br><br>                Task&lt;SampleSet&gt; todaySummationTask = dataController.readTodaySummation(com.huawei.hms.hihealth.data.DataType.<strong><em>DT_CONTINUOUS_STEPS_DELTA</em></strong>);<br>                todaySummationTask.addOnSuccessListener(<strong>new </strong>OnSuccessListener&lt;SampleSet&gt;() {<br>                    @Override<br>                    <strong>public void </strong>onSuccess(SampleSet sampleSet) {<br>                        logger(<strong>&quot;Success read today summation from HMS core&quot;</strong>);<br>                        <strong>isLinkedHuawei </strong>= <strong>true</strong>;<br>                        <strong>if </strong>(sampleSet != <strong>null</strong>) {<br>                            showSampleSet(sampleSet);<br>                            sendLatestStepsToServer(steps);<br>                        }<br>                    }<br>                });<br>                todaySummationTask.addOnFailureListener(<strong>new </strong>OnFailureListener() {<br>                    @Override<br>                    <strong>public void </strong>onFailure(Exception e) {<br>                        <strong>isLinkedHuawei </strong>= <strong>true</strong>;<br>                        String errorCode = e.getMessage();<br>                        String errorMsg = HiHealthStatusCodes.<em>getStatusCodeMessage</em>(Integer.<em>parseInt</em>(errorCode));<br>                        logger(errorCode + <strong>&quot;: &quot; </strong>+ errorMsg);<br>                        Toast.<em>makeText</em>(getContext(), e.getMessage(), Toast.<strong><em>LENGTH_SHORT</em></strong>).show();<br>                    }<br>                }); <br><br>            }<br>            <strong>return null</strong>;<br>        }<br><br>    <em><br><br>    </em>}</pre><pre><strong>private </strong>String showSampleSet(SampleSet sampleSet) {<br> <br>    SimpleDateFormat dateFormat = <strong>new </strong>SimpleDateFormat(<strong>&quot;yyyy-MM-dd HH:mm:ss&quot;</strong>);<br><br>    <strong>for </strong>(SamplePoint samplePoint : sampleSet.getSamplePoints()) {<br>        logger(<strong>&quot;Sample point type: &quot; </strong>+ samplePoint.getDataType().getName());<br>        logger(<strong>&quot;Start: &quot; </strong>+ dateFormat.format(<strong>new </strong>Date(samplePoint.getStartTime(TimeUnit.<strong><em>MILLISECONDS</em></strong>))));<br>        logger(<strong>&quot;End: &quot; </strong>+ dateFormat.format(<strong>new </strong>Date(samplePoint.getEndTime(TimeUnit.<strong><em>MILLISECONDS</em></strong>))));<br>        <strong>for </strong>(com.huawei.hms.hihealth.data.Field field : samplePoint.getDataType().getFields()) {<br>            logger(<strong>&quot;Field: &quot; </strong>+ field.getName() + <strong>&quot; Value: &quot; </strong>+ samplePoint.getFieldValue(field)); <br>        }<br>    }<br><br> <br>}</pre><p>When you run the application you can see a page to link your application into Huawei Health Kit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eP-iR5MVTn2-k2wtZq1mnw.jpeg" /></figure><p>Huawei health kit provides APIs to read, adding, deleting, modifying fitness and health data.</p><p>By integrating the HUAWEI Health SDK into their apps, developers can call the HUAWEI Health Kit APIs to write users’ fitness and health data to the data platform.<br>To make this happen, developers need to:</p><ul><li>Register a HUAWEI ID on the HUAWEI Developers website. Then, create an app, configure the app information, and enable the HUAWEI Health Kit service on the HUAWEI Developers Console.</li><li>Create a project with Android Studio IDE and configure the SDK on which HUAWEI Health Kit depends.</li><li>Implement HUAWEI Health Kit API calling and debugging.</li></ul><p>Reference — <a href="https://developer.huawei.com/consumer/en/doc/health-introduce-0000001053684429-V5">https://developer.huawei.com/consumer/en/doc/health-introduce-0000001053684429-V5</a></p><p>Read more articles on Huawei integration . Hang on for more articles 😉.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26512f354d1" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/integration-huawei-hms-core-to-current-android-application-and-handle-huawei-health-fitness-data-26512f354d1">Integration HUAWEI HMS Core to current android application and handle Huawei health fitness data</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular service worker]]></title>
            <link>https://chirathpereraz1st.medium.com/angular-service-worker-a7332df6c801?source=rss-20023d52af3c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7332df6c801</guid>
            <category><![CDATA[progressive-web-app]]></category>
            <category><![CDATA[service-worker]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Chirath Perera]]></dc:creator>
            <pubDate>Sun, 31 May 2020 12:22:37 GMT</pubDate>
            <atom:updated>2020-05-31T12:22:37.229Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f25CgqeOvkXIglWDSx8JHA.png" /></figure><p>A service worker is a script which runs in the background in a browser. It’s like a proxy. A proxy works as an interface or a gateway between you and internet.It facilitates offline responsibilities. In adding service workers for a an application, so it’s part of a PWA(Progressive Web Apps).PWA is a type of application software that uses modern web capabilities such as progressive, responsiveness, connectivity pendant, app-like, fresh, Safe, discoverable, re-engageable, installable, linkable.</p><h3><strong>Why we need service workers ?</strong></h3><p>A service worker is a script to manage the caching for an application therefore, service worker run in the web browser. Adding a service worker to an Angular application is one of the steps for turning an application into a Progressive Web App (also known as a PWA). Angular developers can take advantage of this service worker and benefit from the increased reliability and performance it provides, without needing to code against low-level APIs.<br>A service worker is used to get push notifications and load the data when application is offline.</p><p>So, what happens when using this service worker file, it caches the all data which are mentioned in the service worker file. That’s why the browser load the old values after deployment.</p><p>In creating service worker, we can define what files to be cached,</p><p>Ex:</p><ul><li>index.html</li><li>favicon.ico.</li><li>Build artifacts (JS and CSS bundles).</li><li>Anything under assets.</li><li>Images and fonts</li></ul><p>Below is an example of contents in service worker json file,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d32252dd0470990ad4729d4454d50d6/href">https://medium.com/media/3d32252dd0470990ad4729d4454d50d6/href</a></iframe><p>Assets are resources that are part of the app version that update along with the app.</p><p>The installMode determines how these resources are initially cached. The installMode can be either of two values:</p><ul><li><strong><em>prefetch —</em></strong> tells the Angular service worker to fetch every single listed resource while it’s caching the current version of the app.</li><li><strong><em>lazy —</em></strong> does not cache any of the resources up front.</li></ul><p>For resources already in the cache, the updateMode determines the caching behavior when a new version of the app is discovered.</p><ul><li><strong><em>prefetch — </em></strong>tells the service worker to download and cache the changed resources immediately.</li><li><strong><em>lazy —</em></strong> tells the service worker to not cache those resources.</li></ul><h3><strong>Adding service worker for any angular application step by step</strong></h3><ol><li>Create a new project</li></ol><pre>ng new swApp</pre><p>2. Add pwa library</p><pre>ng add @angular/pwa</pre><p>After that you can see the couple of new files in your angular application.</p><ol><li>go to <strong><em>src</em></strong> you can see a file called <strong><em>manifest.webmanifest — </em></strong>You can customize any of properties by changing the relevant values in manifest.webmanifest. This file contains about a web application in a JSON text file.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/befb2ee9bafe1cbbd95c26c45e49339f/href">https://medium.com/media/befb2ee9bafe1cbbd95c26c45e49339f/href</a></iframe><p>2.<strong> ngsw-config.json —</strong> it has files and data URLs the Angular service worker should cache and how it should update the cached files and data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93a092f20af9e94351ff3fb6e3eae106/href">https://medium.com/media/93a092f20af9e94351ff3fb6e3eae106/href</a></iframe><p><strong>app.module.ts</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7925ecd9fb6326ff03f905e66eaddad/href">https://medium.com/media/d7925ecd9fb6326ff03f905e66eaddad/href</a></iframe><p>You can see the line that AppModule tries to register the service worker script in the browser by loading the ngsw-worker.js. This js file loads in a separate HTTP request by using register method.</p><p>If you test service workers in a test environment in terms of a new instance you should add your instance name as a prefix.</p><p>ex- ‘/instanceName/ngsw-worker.js’.</p><pre><strong><em>abc-dev.abc.com/sw-test/login</em></strong></pre><p>Above URL is an example of a test environment.So in that your instance name is sw-test. Therefore you have to register your service worker in appModule like this -</p><pre>ServiceWorkerModule.register(&#39;/<strong><em>sw-test</em></strong>/ngsw-worker.js&#39;, { enabled: environment.production })</pre><p>After run the</p><pre>ng build --prod </pre><p>You can see the generated service worker javaScript files in the file location. (/dist).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*im-TWeRcYB6oyggPuG7iew.png" /></figure><p>Before do the ng serve you have to set a http server in your loaclhost. Because service workers don’t run in local. So, go to your dist folder typing this command</p><pre>cd dist/your app name -&gt; cd dist/swApp</pre><p>Then type in the cmd</p><pre>http-server -o </pre><p>Then it opens the browser automatically, on browser go to inspect-element then select application</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zkpgyagHdEl8Jk2rcMje4A.png" /></figure><p>So you can see the service worker received time and the service worker file. The browser stores this time as a timestamp.</p><h3><strong>Update Service Worker</strong></h3><p>We need to check that a new version is available after every deployment otherwise the browser caches old application version after reloading. So we have to check new version is available periodically. We can add SwUpdate() method to check a new version after every deployment. Then if there is a new version of application is available, the browser will reload the page automatically. we can add this method in ngOnInit of AppComponent.ts.</p><p><strong><em>app.component.ts</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c69f21ea77dc18bce0e2deba5bab8f81/href">https://medium.com/media/c69f21ea77dc18bce0e2deba5bab8f81/href</a></iframe><h3><strong>Summary</strong></h3><p>Using this service workers can be a benefit for loading an application faster and manages caching in an application. A service worker is a script that is run in the browser background. Adding a service worker to an Angular application is one of the steps for turning an application into a Progressive Web App (PWA). There are technical components of PWA. Those are HTTPS, Manifest.json and Service worker. Therefore, an service worker requires HTTPS to run in the browser.</p><p>Reference — <a href="https://angular.io/guide/service-worker-intro">https://angular.io/guide/service-worker-intro</a></p><p>Read more articles on angular service workers. Hang on for more articles 😉.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7332df6c801" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular simple dynamic template-driven form for beginners]]></title>
            <link>https://levelup.gitconnected.com/angular-simple-dynamic-template-driven-form-for-beginners-ee230a76ef77?source=rss-20023d52af3c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee230a76ef77</guid>
            <category><![CDATA[dynamic-form]]></category>
            <category><![CDATA[angular-for-beginners]]></category>
            <category><![CDATA[template-driven-form]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Chirath Perera]]></dc:creator>
            <pubDate>Sun, 17 May 2020 08:49:33 GMT</pubDate>
            <atom:updated>2020-07-26T00:01:33.589Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*awznYwONd8QBhOu7aKacng.png" /></figure><p>In this blog, you will learn how to approach Angular template driven forms. Angular forms help you to create custom form controls and validations. The form controls can hold data values and form validation data. There are two types of handling user inputs by forms in angular. Those are reactive forms and template driven forms. Both types of forms catch user events from the view.</p><p>Template driven forms are model driven forms driven by directives in a template. Template driven forms are approached by angular JS users but sometimes template driven forms will be used for complex systems. For instance, if you want to dynamically set to validate a particular form filed you can use template driven forms. In the template driven forms uses two way data binding in terms of it uses ngModel despite formControl and fromGroups.</p><h3><strong>Form structure</strong></h3><p>I am going to create a simple form that is able to create new form fields. The number of form-fields depends on the user. It can be changed at run time. <br>However, each form entry requires a name like formControlName in reactive forms and the state of the form as a whole that is a collection of individual form fields. Each form filed is assigned a unique id property. Therefore, template driven form controls need to be uniquely named. We can generate form fields using a unique control name. In this dynamic form, it has been used the current timestamp as a unique id or you can create a method to get random numbers to assign for this unique id. So it can get through with parent NgForm.</p><p>First, import formsModule to main module ex:- app.module.ts then create an interface to describe an object. You have to set some properties you want to this interface.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69211b607e6afa88c8aeff599dbca458/href">https://medium.com/media/69211b607e6afa88c8aeff599dbca458/href</a></iframe><p>As you can see, you can generate many forms by clicking the addForm button. So this template driven form uses the ngFor directive to loop each instances, assigning set of ngModel-driven inputs. Initially, the form has one instance. Each form should have a unique id to set the fact of template driven form. The form uses the ngModel directive instead of using form-control.</p><h3><strong>NgModel Validation</strong></h3><p>I have added simple validation to teach how we can add validation on html. So you can add HTML 5 validations like minlength validation, maxlength, pattern validation, email validation and etc.</p><p>Angular is always listening the form validity and this functionality is common for both reactive and template-driven forms. There 3 types of validations in an angular form,</p><ul><li><em>touched or untouched</em></li><li><em>valid or invalid</em></li><li><em>pristine or dirty</em></li></ul><p>I have not mentioned about custom validations which are not HTML 5 validation, in angular forms. If you want to custom validation check out this article.</p><p><a href="https://medium.com/swlh/how-to-validate-angular-forms-with-template-driven-forms-8b7357b67cea">How to Validate Angular Forms with Template Driven Forms</a></p><h3><strong>Summary</strong></h3><p>Angular template driven forms is based on models and it’s simple compared with angular reactive forms. The angular identifies the form tag then it changes the form to Angular form. Unique ids are assigned to each form element and ngModels also. ngModel converts each form elements to formControls like in reactive forms.</p><p>Read more articles on angular forms. Hang on for more articles 😉.</p><p><strong>Reference </strong>— <a href="https://angular.io/guide/forms"><em>https://angular.io/guide/forms</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee230a76ef77" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/angular-simple-dynamic-template-driven-form-for-beginners-ee230a76ef77">Angular simple dynamic template-driven form for beginners</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>