Sunday, June 26, 2016
In the previous blog post we got AngularJS to work with a module and a controller. However, we put everything in the global scope. The problem with that is that there are many JavaScript libraries that might be using the same variables as we are, or if we are working with other developers, there might be some unforeseen conflicts. The way we can mitigate this problem is to wrap our modules and controllers in an anonymous function. Think of an anonymous function as a wrapper or a container to hold our modules and controllers. Another term developers like to refer to anonymous function is an IIFE. Whatever it's called it's always good practice to avoid putting things in the global environment if it can be avoided.
Here are the steps to take the modules and controllers out of the global environment:
1. First let's wrap the module in an anonymous function. The source code for the app.js file should look like the following
The code above wraps the application in anonymous function and assigned to the variable call "app"
2. Now open the "bankController.js" in the "controllers" folder and wrap the "bankController" in anonymous function, the source code for the file should look like the following
3. Open up the "index.html" file and make sure the source code looks like the following.
4.If you open the file you will see that application still works
In this tutorial we've taken some steps to future proof our application so that we are not working in the global environment
Posts In The AngularJS SPA Application Series:
1. First let's wrap the module in an anonymous function. The source code for the app.js file should look like the following
(function(){ 'use strict'; var app = angular.module('bankApp',['bankController']); })();
The code above wraps the application in anonymous function and assigned to the variable call "app"
2. Now open the "bankController.js" in the "controllers" folder and wrap the "bankController" in anonymous function, the source code for the file should look like the following
(function(){ 'use strict'; angular.module('bankController',[]) .controller('bankController',["$scope",function($scope){ $scope.bankAppName="My Bank Application"; }]); })();
3. Open up the "index.html" file and make sure the source code looks like the following.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Bank Application</title> <link rel="stylesheet" type="text/css" href="app.css"> </head> <body ng-app="bankApp" ng-controller="bankController"> {{bankAppName}} <script type="text/javascript" src="js/lib/angular/angular.js"></script> <script type="text/javascript" src="js/app.js"></script> <script type="text/javascript" src="js/controllers/bankController.js"></script> </body> </html>
4.If you open the file you will see that application still works
In this tutorial we've taken some steps to future proof our application so that we are not working in the global environment
Posts In The AngularJS SPA Application Series:
- Setting Up Angular-Seed
- AngularJS - Setting up ACME Bank
- Refactor Code to Not Use Global Variables (Shopping List App)
- Installing MongoDB
- Create a MongoDB Configuration FIle
- Install mongoDB as a Windows Service
- Installing Express generator
- Installing ExpressJS Application Server
- Creating The SPA Project Folder Structure
- Setup Express To Serve Static Files
- Setup The Shopping Application For Heroku And Testing It Locally
- Deploy Shopping List Application To Heroku
- Install RoboMongo GUI for MongoDB
Subscribe to:
Post Comments (Atom)
Search This Blog
Tags
Web Development
Linux
Javascript
DATA
CentOS
ASPNET
SQL Server
Cloud Computing
ASP.NET Core
ASP.NET MVC
SQL
Virtualization
AWS
Database
ADO.NET
AngularJS
C#
CSS
EC2
Iaas
System Administrator
Azure
Computer Programming
JQuery
Coding
ASP.NET MVC 5
Entity Framework Core
Web Design
Infrastructure
Networking
Visual Studio
Errors
T-SQL
Ubuntu
Stored Procedures
ACME Bank
Bootstrap
Computer Networking
Entity Framework
Load Balancer
MongoDB
NoSQL
Node.js
Oracle
VirtualBox
Container
Docker
Fedora
Java
Source Control
git
ExpressJS
MySQL
NuGet
Blogger
Blogging
Bower.js
Data Science
JSON
JavaEE
Web Api
DBMS
DevOps
HTML5
MVC
SPA
Storage
github
AJAX
Big Data
Design Pattern
Eclipse IDE
Elastic IP
GIMP
Graphics Design
Heroku
Linux Mint
Postman
R
SSL
Security
Visual Studio Code
ASP.NET MVC 4
CLI
Linux Commands
Powershell
Python
Server
Software Development
Subnets
Telerik
VPC
Windows Server 2016
angular-seed
font-awesome
log4net
servlets
tomcat
AWS CloudWatch
Active Directory
Angular
Blockchain
Collections
Compatibility
Cryptocurrency
DIgital Life
DNS
Downloads
Google Blogger
Google Chrome
Google Fonts
Hadoop
IAM
KnockoutJS
LINQ
Linux Performance
Logging
Mobile-First
Open Source
Prototype
R Programming
Responsive
Route 53
S3
SELinux
Software
Unix
View
Web Forms
WildFly
XML
cshtml
githu
Js has really been helpful 🙌🙌 thanks a lot
ReplyDeleteThank you! I tried to be as clear as possible. Sometimes books can be dry :)
DeleteWe share this js coding is really helpful to me. And it's this site content is good very useful to me.
ReplyDeleteThank you!
DeleteThanks for this informative blog please keep posting more often as it might help someone who is looking to gain more knowledge.
ReplyDeleteSelenium Training in chennai | Selenium Training in anna nagar | Selenium Training in omr | Selenium Training in porur | Selenium Training in tambaram | Selenium Training in velachery
Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot.
ReplyDeleteData Science certification Online Training in bangalore
Data Science certification courses in bangalore
Data Science certification classes in bangalore
Data Science certification Online Training institute in bangalore
Data Science certification course syllabus
best Data Science certification Online Training
Data Science certification Online Training centers
Very interesting blog Thank you for sharing such a nice and interesting blog and really very helpful article.
ReplyDeleteSAP PP Training in Bangalore
Best SAP PP Training Institutes in Bangalore
Thank you for excellent article.You made an article that is interesting.
ReplyDeleteSAP HCM Online Training
SAP HCM Classes Online
SAP HCM Training Online
Online SAP HCM Course
SAP HCM Course Online
Hi Frankcompressors here, Blog is very interesting, thanks for sharing.
ReplyDeleteI recently visited your blog profile. I was really impressed with blogging skills and knowledge.
ReplyDeleteVist our website too, We are Screw Dilator suppliers.
Really amazing experience to visit your blog, thanks a lot for sharing with us. Visit Ogen Infosystem for creative website designing and ppc services at best price in Delhi.
ReplyDeleteWeb Designing Company
Nice blog
ReplyDeleteIf you know so much about code, Why don't you start youtube channel about it? Now is very easy to get youtube subscribers. Just go to this site https://soclikes.com/buy-youtube-subscribers and buy. That is all
ReplyDeleteGreat Content & Thanks For Sharing With oflox. Do You Want To Know How To Make Money From Mitron App
ReplyDeleteĐặt mua vé tại Aivivu, tham khảo
ReplyDeletegia ve may bay di my
săn vé máy bay giá rẻ tết 2021
vé máy bay đi Canada vietnam airline
ve may bay di Phap gia bao nhieu
vé máy bay đi Anh bao nhiêu
vé máy bay giá rẻ khuyến mãi
combo đà nẵng
combo vinpearl nha trang 2021
When I study programming I read this post https://blog.nus.edu.sg/sarkar/how-to-become-a-tiktok-star-while-studing/ and start my tiktok blog. How I grateful to author of this post. Tiktok is the most lovely thing in my life and I have great results there
ReplyDeleteNice to read your article. This has really made good thing.
ReplyDeletePerl training in bangalore
Online football betting ufabet will definitely get the price of water more than anywhere else. When compared with other companies such as other water 1.90, we water 1.94 or more, depending on the pair. We guarantee the price of 4 sets of football betting with us, starting with a minimum of only 10 baht, because our website has no minimum deposit with an automatic system
ReplyDeletenice Post thanks for the information, good information & very helpful for others.
ReplyDeleteSailpoint Training
Looker Training
Oracle Fusion HCM Training
You have described it so deeply. Every normal person can easily understand how a data network works. But some people mix it with data center. Fungible is a company that is providing the best data center solution. From that website, you can easily understand what is data center.
ReplyDeleteI’m happy I located this blog! From time to time, students want to cognitive the keys of productive literary essays composing. Your first-class knowledge about this good post can become a proper basis for such people. nice one website management
ReplyDeleteI was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post. ppc management
ReplyDeleteAwesome article with great information provided by your article, here I would like to thank you guys for sharing such a fantastic blog. Regards digital marketing
ReplyDeletemarine equipment singapore
ReplyDeletemarine spare part
Fantastic goods article.I understood your stuff before and you are great..Turkey travel visa and visa required for Turkey, you need to fill visa application form Turkey online through Turkey e visa.
ReplyDeleteHi, I want to subscribe for this blog to get most up-to-date updates, so where can i do it please help out. 카지노
ReplyDelete(mm)
luxury party wearantique gold suede hijab
ReplyDeleteluxury party wearsilver fox suede hijab
Attractive component of the material. I just stumbled across your web site and accession capital to say that I really enjoyed your site. With just a few clicks, foreign nationals can apply for a Kenya online visa application from their home. Fill the form with accurate and complete information about the passenger's data.
ReplyDeleteAivivu đại lý vé máy bay, tham khảo
ReplyDeletevé máy bay đi Mỹ bao nhiêu tiền
chuyến bay từ mỹ về việt nam tháng 1/2021
vé máy bay từ canada về việt nam
giá vé máy bay từ nhật về việt nam
vé máy bay hàn quốc hà nội
Vé máy bay từ Đài Loan về VN
Chuyến bay cho chuyên gia nước ngoài
xs
ReplyDeleteFNP Gardens is a unit of Ferns N Petals that offers a range of wedding venues and banquet halls in Delhi and Gurgaon. The beautiful venues offer all amenities to host elegant weddings, as well as pre-wedding and post-wedding functions. FNP Gardens offer a combination of spaces that includes both indoor and outdoor wedding venues. The farmhouses are known for their aesthetically designed lush green spaces, understated elegance as well as excellent hospitality services. All the venues have their own uniqueness and are designed differently from each other to which makes them popular amongst other banquet halls in Delhi and Gurgaon for weddings. The following list highlights all the Gardens: The Ritz, The Riviera, The Riviera House, Shagun Farms, Chattarpur Central, Pavilion, Opulent Hotel, Udman, Vilasa, The Kundan. These venues are noted as one of the top banquet halls in Delhi for offering the best services for any kind of event
ReplyDeletewedding venues in delhi
banquet halls in gurgaon
banquet halls in south delhi
wedding venues in chattarpur
banquets in west delhi
wedding venues in greater noida
Sarai Kale Khan Cremation Ground
This is really a good article. The Government of Ukraine grants the e-visa online. Do you have any idea about the Ukraine visa fees?. The Ukraine visa fee is dependent on your nationality and type of visa.
ReplyDeleteAmazing post…. Travelers from around 169 countries can now apply for an online Indian visa application with 1 month, 5 years validity of 1 year.Travelers can opt for double or multiple entry, depending on the validity of the visa.
ReplyDeleteI'm writing on this topic these days, 메리트카지노, but I have stopped writing because there is no reference material. Then I accidentally found your article. I can refer to a variety of materials, so I think the work I was preparing will work! Thank you for your efforts.
ReplyDeleteI definitely enjoy every little bit of it and It is a great website. I want to thank you for the content. I learn a lot from your blog. Good job! You guys do a great blog and have some great content. Keep up the good work.
ReplyDeleteBest School Management Software
very informative blog thank you
ReplyDeleteshivling with nandi
vishnu laxmi murti
Great blog wonderful information you have shared thanks for the detailed informative content.
ReplyDeleteTechimply
Wow.. Very informative article thanks for sharing please keep it up.. Pakistan visa fees depend on your visa type and nationality.
ReplyDeleteNice post. I love to keep up the good work. e business visa India, The Indian business visa application form can be completed from home online via India e visa portal.
ReplyDeleteto know more information about AI service desk and help desk for employee. click here : https://bit.ly/3BStWpj
ReplyDeleteWhen I get to meet people with expertise, many of them with PhDs, others straight from top universities for business, I can see an air of confidence in their posture. It's a confidence that someone who comes from an humble background or with no formal education might not possess. In most cases when we begin to talk about knowledge, the aura disappears. What fascinates me is how the formal structure of education have stifled their curiosity. However I have met people from remote villages -who are full of enthusiasm as well as creativity and innocence.
ReplyDeleteHii everyone, Thanks for sharing. Do you know what Indian visa photo requirements are? You can read India visa photo requirements on our indian visa website. We explained all details related to the India visa photo on our page.
ReplyDelete
ReplyDeleteHii friends, this is great. If you want to learn more about Turkish e visa you can visit our Turkey e visa website. And read here all info about Turkey visa online.
Brilliant! Incomprehensible article man! Thanks, although I ran into problems with your RSS feed. I can't appreciate the inspiration why I can't do this. Are there other people with similar problems with RSS? Can you answer all the individuals who have the right answer? Highly valued !!
ReplyDeleteVisit viral times for tech news.
Thank you...
ReplyDeleteOunce To Cup
8 ounces to cups
This is also a very good post which I really enjoyed reading. It's not every day that I'm likely to see something like this. You can fill your Indian business visa application form online within 5 to 10 minutes and then pay India business visa cost online.
ReplyDeleteGreat blog right here! Also your web site loads up very fast! Hello everyone, Many people ask, what is India e tourist visa, India Tourist e-Visa is an electronic travel permit that every foreign traveler needs to obtain before traveling to India. Foreign nationals from more than 169 countries can apply for a tourist visa India online to enter India.
ReplyDelete
ReplyDeleteWow , there is an excellent conversation about this section here on this site. What is the Vietnam e visa apply online on the web ? It is extremely easy to apply for an e-Visa for Vietnam, which is accessible to inhabitants of 80 nations.
Nice useful post… I am here for the first time and this hit me directly... Data Entry Services play a very vital role in any organization. We provide the best Data entry service in all over the world at an affordable price. The charges of our service fit in any budget. So go and check out the cost and charges.
ReplyDeleteThat is the same thing that I am trying to find. Thanks for sharing this information... The application process of e visa Turkey is easy and simple, the application form of Turkey evisa is easy to fill out for everyone, if you want to apply for visa check out the page.
ReplyDeleteThe International Criminal Police Organization (ICPO; French: Organisation internationale de police criminelle), commonly known as Interpol (UK: /ˈɪnt.ər.pɒl/ INT-ər-pol, US: /-poʊl/ -pohl),[3] is an international organization that facilitates worldwide police cooperation and crime control. Headquartered in Lyon, France, it is the world's largest international police organization, with seven regional bureaus worldwide and a National Central Bureau in all 195 member states.[4]
ReplyDeleteInterpol was conceived during the first International Criminal Police Congress in 1914, which brought officials from 24 countries to discuss cooperation in law enforcement. It was founded on September 7, 1923 at the close of the five-day 1923 Congress session in Vienna as the International Criminal Police Commission (ICPC),[5] and adopted many of its current duties throughout the 1930s. After coming under Nazi control in 1938, the agency was effectively moribund until the end of World War II. In 1956, the ICPC adopted a new constitution and the name Interpol, derived from its telegraphic address used since 1946.[6]
Interpol provides investigative support, expertise, and training to law enforcement worldwide, focusing on three major areas of transnational crime: terrorism, cybercrime, and organized crime. Its broad mandate covers virtually every kind of crime, including crimes against humanity, child pornography, drug trafficking and production, political corruption, intellectual property infringement, and white-collar crime. The agency also facilitates cooperation among national law enforcement institutions through criminal databases and communications networks. Contrary to popular belief, Interpol is itself not a law enforcement agency.
Interpol has an annual budget of €142 million, most of which comes from annual contributions by member police forces in 181 countries. It is governed by a General Assembly composed of all member countries, which elects the Executive Committee and the President (currently Ahmed Naser Al-Raisi of the United Arab Emirates) to supervise and implement Interpol's policies and administration. Day-to-day operations are carried out by the General Secretariat, comprising around 1,000 personnel from over 100 countries, including both police and civilians. The Secretariat is led by the Secretary-General, currently Jürgen Stock, the former deputy head of Germany's Federal Criminal Police Office.
Pursuant to its charter, Interpol seeks to remain politically neutral in fulfilling its mandate, and is thus barred from interventions or activities that are political, military, religious, or racial in nature and from involving itself in disputes over such matters.[7] The agency operates in four languages: Arabic, English, French and Spanish.[4]
Good blog post Azure Data Factory Training in Hyderabad
ReplyDeleteIt’s clearly an exceptional and very useful fact. Thanks for sharing this helpful data with us. CEA Aviation is one of the Best DGCA Ground Classes in delhi. It gives admission to all of the aspirants seeking to start with Ground classes. You can enrol for Best Ground training for DGCA checks with us. Once you're clear with DGCA exam Counsellor Desk will assist you in choosing the best flight academy overseas.
ReplyDelete28s fujikura
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThank you for the blog.
ReplyDeletePython Training in Chennai
Python Online Course
Python Training in Bangalore
Thank you for this blog. Share more like this.
ReplyDeleteEthical Hacking Course in Chennai
Ethical Hacking Online Course
Ethical Hacking course in Bangalore
This comment has been removed by the author.
ReplyDeleteLooking for a mommy makeover in Hawaii? Face and Body offers a range of cosmetic procedures to help you look and feel your best. Our experienced surgeons are committed to providing top-notch care to ensure your satisfaction. Get started today!
ReplyDeleteThanks for this article.
ReplyDeleteGraham Builder is the premier home renovation and remodeling contractor in Honolulu. We specialize in kitchen, bathroom, and full-house remodels. Our experienced team of professionals will help you create the ideal space for your home. Contact us today to get started.
If you are looking for a reputable
ReplyDeleteGet personal accountant services in Brisbane from Wow! Advisor. Our certified accountants provide tax, business advisory and financial advice tailored to your needs. We offer efficient and reliable assistance to help you achieve your financial goals.
Nice informative content. Thanks for sharing the valuable information.
ReplyDeleteRPA Training in Chennai
RPA Training Online
RPA Training In Bangalore
RPA Course in Coimbatore
Nice Post! I appreciate you providing this lovely content because it was enjoyable to read and helped me stay informed. Please continue blogging.
ReplyDeletePower BI Training In Hyderabad
hi
ReplyDeleteThis is an excellent initiative! Eliminating global variables in an AngularJS SPA, especially in a Bank App, is a smart move. It not only enhances security but also promotes cleaner, more maintainable code. Kudos for sharing this valuable advice!
ReplyDeleteGreat article! I appreciate you sharing valuable information.
ReplyDeletevisit:
Mulesoft Training In Hyderabad
MuleSoft training is a popular choice for professionals who want to learn how to build and manage integrations. MuleSoft is a leading integration platform that enables businesses to connect any system, data, or API, regardless of its technology stack or location.
ReplyDeleteThere are many different ways to get MuleSoft training. MuleSoft itself offers a variety of courses, both online and in-person. These courses are designed to teach students the fundamentals of MuleSoft and how to use it to solve real-world integration challenges.
In addition to MuleSoft's own training courses, there are also many third-party companies that offer MuleSoft training. These companies offer a variety of different course formats,
nice article
ReplyDeletehttps://careergearup.com/clat-coaching-in-hyderabad/
https://careergearup.com/sociology-optional-syllabus/
https://careergearup.com/sociology-optional-coaching-online/
https://careergearup.com/clat-coaching-in-hyderabad/
https://careergearup.com/top-10-csat-coaching-institutes-in-hyderabad/
Nice article
ReplyDeleteca coaching in hyderabad
ca intermediate course
ca final course
ca foundation course
Nice article
ReplyDeletecma coaching in hyderabad
cma foundation course
cma intermediate course
cma final course
Nice article
ReplyDeletevba macros course
advanced excel course
power bi course in hyderabad
microsoft office essentials course
advanced excel course in hyderabad
Animation Company in India
ReplyDeleteVR Company in India
ar filter
Web AR
Your blog post is a mesmerizing exploration of intricate concepts, skillfully combining clarity with profound insights. The seamless integration of well-researched facts and personal perspectives constructs a narrative that captivates and enlightens. Your distinct voice and thoughtful perspective enrich the discourse, ensuring readers experience an engaging and enlightening journey. Eagerly looking forward to more of your exceptional contributions.
ReplyDeleteNice Blog Keep Posting.
ReplyDeleteReact-Js training institute in Hyderabad
thanks for valuable info
ReplyDeletegcp training in hyderabad
About Excellogics
ReplyDeleteWe are Passionate About Building Excel Tools for the industry
Ever Wished You Could Do More With Excel? Our Training Can Help You Take Excel To The Next Level. We’re The Team That’s Passionate About Building Excel Tools For The Industry, And We’re Always Working On Something New. Check Back For Updates On Our Blog.
https://excellogics.co
Perfectly written. Thanks for sharing the article with us!
ReplyDeleteAzure Data Factory Training in Hyderabad
Thanks for sharing the valuable information.java full stack training in kphb
ReplyDelete"Great article, felt good after reading, worth it.
ReplyDeletei would like to read more from you.
keep posting more.
also follow Propmtengineeringcourseinhyderabad"
"Great article, felt good after reading, worth it.
ReplyDeletei would like to read more from you.
keep posting more.
also follow Mern Stack course in hyderabad"
"Top Digital Marketing Agency In Hyderabad
ReplyDelete"
This article really struck a chord with me. It beautifully captures the complexity of human emotions and the journey of self-discovery. The way it delves into the intricacies of our thoughts and feelings is truly profound. It's comforting to know that others experience the same struggles and triumphs as I do. This piece reminds me to embrace my uniqueness and cherish every moment of growth. Thank you for sharing such an insightful perspective.
ReplyDeleteVery interesting blog Thank you for sharing such a nice and interesting blog and really very helpful article.
ReplyDeleteFlutter Training in Hyderabad
I felt a deep connection to this blog post. The author expressed thoughts and feelings I've often struggled to articulate. Every sentence resonated with my own experiences, making me feel seen and understood. The insights shared are both comforting and thought-provoking. Thank you for sharing your wisdom and giving us all something valuable to reflect on.
ReplyDeleteI found this blog post incredibly insightful. It’s rare to see such candid reflections on the struggles we all encounter but often keep to ourselves. Your discussion on balancing personal growth with daily life resonated deeply with me. The practical suggestions you provided are both useful and easy to integrate into my routine. Additionally, the personal stories you shared added authenticity and made the advice more relatable. I’m looking forward to reading more of your work; keep it up.
ReplyDeleteReading your blog post is like embarking on a spiritual pilgrimage, traversing the landscapes of the mind and soul in search of deeper meaning and understanding. Your words are not just sentences on a page; they are beacons of light illuminating the path towards enlightenment. Thank you for your wisdom, your guidance, and your unwavering commitment to truth.
ReplyDeletenice blog thanks for posting
ReplyDeleteAzure Data Factory Training In Hyderabad