Intro
In Angular 1.5 we got the Component, it is an improvement on our old pal the Directive. In fact a Component is just a Directive with some default settings, and a nicer API.Here is a great blog post by Todd Motto which explains Components in dept, and compares them to ordinary directives.
A tale of two Components
Components have one other nice feature, they are closely aligned to the way Angular 2.0 will work. In fact if you squint your eyes you cannot really see the difference:Here is a nameCard Component in Angular 1.x:
angular.module('myApp',[])
.component('nameCard', {
bindings: {
name: "@"
},
controllerAs: 'nameCardController',
template: `
<h1>Hi my name is</h1>
<h2>{{ nameCardController.name }}</h2>
`
});
Here is a nameCard Component in Angular 2.x:
@Component({
selector: 'name-card',
template: `
<h1>Hi my name is</h1>
<h2>{{ name }}</h2>
`
})
export class NameCardComponent {
@Input() name: String;
}
Here is how you use both of them:
<name-card name="Maarten"></name-card>
Why use Components in Angular 1.5
So using Components in Angular 1.5 gets you pretty close the way Angular 2.0, works, which makes migrating to 2.0 a lot easier.
That is why we at 42 decided to use Components instead of Controllers and Element Directives (with restrict E), to prepare us for the migration ahead.
ui-router as a Component Router
But we hit one problem: we use ui-router, which is not geared towards using Components... or is it?
Turns out you can get ui-router to work with components quite easily:
angular.module('myApp', ['ui.router'])
.config(function($stateProvider) {
$stateProvider.state('home', {
url: '/greetings',
template: '<name-card name="Maarten"></name-card>'
})
})
.component('nameCard', {
bindings: {
name: "@"
},
controllerAs: 'nameCardController',
template: `
<h1>Hi my name is</h1>
<h2>{{ nameCardController.name }}</h2>
`
});
Basically what we do is say that the template of the 'home' state is simply the use of a single Component. This way there is no need to define a controller and a separate template HTML file for the state.
You can see it live here: http://codepen.io/anon/pen/jAzOqQ?editors=0010#greetings
Dealing with $stateParams
The first example hard-coded my name into the Component, what if we want to take a name from the URL instead, to make it more dynamic:
angular.module('myApp', ['ui.router'])
.config(function($stateProvider) {
$stateProvider.state('home', {
url: '/greetings/:name',
template: '<name-card></name-card>'
})
})
.component('nameCard', {
controllerAs: 'nameCardController',
controller: function($stateParams) {
const nameCardController = this;
nameCardController.name = $stateParams.name;
},
template: `
<h1>Hi my name is</h1>
<h2>{{ nameCardController.name }}</h2>
`
});
In this example we simply inject the $stateParams into the controller
for the nameCard Component, and use it to get the name from the URL.
You can see it live here: http://codepen.io/anon/pen/XKEWpW?editors=0010#/greetings/Gertrude
Dealing with resolves
What if we have resolves in your states how do we deal with that? The answer is by using a 'route' controller like this:
angular.module('myApp', ['ui.router'])
.config(function($stateProvider) {
$stateProvider.state('home', {
url: '/greetings',
template: '<name-card name="homeRouteController.name"></name-card>',
controllerAs: "homeRouteController",
controller: function(name) {
const homeRouteController = this;
homeRouteController.name = name;
},
resolve: {
name: function() {
/*
Of course in real life this would get
some data from some REST API.
*/
return "Maarten";
}
}
})
})
.component('nameCard', {
bindings: {
name: "<"
},
controllerAs: 'nameCardController',
template: `
<h1>Hi my name is</h1>
<h2>{{ nameCardController.name }}</h2>
`
});
The job of a 'route' controller is acting purely as glue between the resolve and the Component. Its job is to inject all the 'resolves' and them on the scope, so that the template can access them.
Also note that the binding in the Component uses a one way binding (<) now instead of an interpolation binding (@), because name is now a variable instead of a string.
You can see it live here: http://codepen.io/anon/pen/ZOxEZz?editors=0010#greetings
A Nuclear Weapon
There is one final weapon in our arsenal: the templateProvider, it allows you to dynamically create a template which ui-router will use.
We can implement the example from 'Dealing with $stateParams' with templateProvider like this:
angular.module('myApp', ['ui.router'])
.config(function($stateProvider) {
$stateProvider.state('home', {
url: '/greetings/:name',
templateProvider: function($stateParams) {
const name = $stateParams.name
return `<name-card name="${name}"></name-card>`;
}
})
})
.component('nameCard', {
bindings: {
name: "@"
},
controllerAs: 'nameCardController',
template: `
<h1>Hi my name is</h1>
<h2>{{ nameCardController.name }}</h2>
`
});
You can see it live here: http://codepen.io/anon/pen/XKEWpW?editors=0010#/greetings/barry
In the templateProvider you have access to all resolves and you can inject any service / factory that you need.
In this example we use it to create a route which passes the 'name' from the $stateParams as a string. This way the nameCard does not need to use a one way binding, but has an interpolation binding instead.
The reason I think this is a nuclear weapon is because you do not really need it. TemplateProviders hide the 'router' from your Component and I feel that this is dishonest. A Component should be aware that it represents a 'state' by injecting the $stateParams in its controller.
In Angular 2.0 when a Component needs a parameter from the route it will get it himself, see this blog post by Victor Savkin under the heading "Using Params". That is why I advocate always injecting the $stateParams in the Component so it is closer to best practices in Angular 2.0.
ui-router 1.0.0
In ui-router 1.0.0 it is going to be even easier to route to a Component, because it will be directly supported by ui-router. See this page: https://ui-router.github.io/tutorial/ng1/hellosolarsystem on how to do this.
Conclusion
Using Components in Angular 1.5 will make migrating easier.
Using ui-router as a Component router is really not that hard.
That is it, happy routing!
Thank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our. 192.168.0.1
ReplyDeleteWith the right router bit, users can cut, trim, and shape workpieces with staggering versatility; these bits are available in numerous profiles and can be custom fabricated to create virtually any profile conceivable.wifi router
DeleteAwesome blog, thank you so much for sharing such amazing information with us. For a custom website design and SEO Services at the minimum cost.
ReplyDeleteWebsite Designing Company in Delhi
Needed to compose you a tiny note to finally thank you very much yet again for your personal splendid methods you have discussed above. It is strangely open-handed with people like you to provide publicly all that a number of people would have marketed as an electronic book to generate some bucks for their own end, primarily now that you could possibly have tried it if you ever wanted. These inspiring ideas likewise acted like a fantastic way to know that the rest have the same dreams really like my personal own to see a whole lot more concerning this problem. I’m sure there are thousands of more enjoyable times in the future for many who check out your blog. design agencies sf
ReplyDeleteExcellent publish from specialist also it will probably be a fantastic know how to me and thanks very much for posting this useful data with us all. design agencies sf
ReplyDeleteTo be sure using your thoughts here and I like your blog! I’ve bookmarked it to ensure I can come back & read more sometime soon. ipad device template
ReplyDeleteThere is definately a great deal to know about this subject. I like all of the points you've made. wifi router for multiple devices
ReplyDeleteAmazing blog, thank you so much for sharing this valuable blog. Visit Protrek Adventure for affordable Everest Base Camp Trek and Three Passes Trek with the best guidance.
ReplyDeleteEverest Base Camp Trek
I want to thank you for this excellent information, I definitely enjoyed this post. I have got you saved as a favorite to look at new stuff you post.
ReplyDeleteEssay Assignment Help Middlesex
Accounting Information System Assignment Help
Macroeconomics Assignment Writing
Switch is a gadget which permits more than 1 PC to get to the Internet simultaneously. We should take a model. You have 2 PCs and you have 1 modem that is given by your Internet specialist organization (ISP). jiofi.local.html
ReplyDeleteWe offer a tool to identify your router's IP address 192.168.0.1 - 192.168.0.1 Router Admin Login. If you spot devices that shouldn't be there, check where they're coming from and whether they should be there.
ReplyDeleteThanks for the post. I have also using JioFi wifi router.
ReplyDeleteResources:-
jioupdate.in/jiofi-local-html/
jio4gvoiceapk.in/jiofi-local-html/
Keep going on this amazing blog. Visit RP Paper Impex for Business Diary Manufacturer and Tissue Paper Roll Suppliers in India at an affordable price.
ReplyDeleteBusiness Diary Manufacturer in India
This blog was really amazing and valuable, thank you so much for sharing this blog. Sarswati Enterprises is a leading Pilfer Proof Caps Making Machinery and Die Set Manufacturers in Delhi, for more information visit our website.
ReplyDeletePilfer Proof Caps Making Machinery
This comment has been removed by the author.
ReplyDeletevery best post keep it up... and also see more wifi related info at jiofi.local.html
ReplyDeleteGreat Post, thanks for sharing such an amazing blog with us. Veramed is one of the leading Quality Herbal and Ayurvedic Products and Anti Hairfall Ayurvedic Hair Care Products in India.
ReplyDeleteBest Quality Herbal and Ayurvedic Products in India
ReplyDeletemicrosoft word not responding mac
word not responding mac
word not responding
word won t open on mac
I really appreciate the information that you have shared on your Blog. Thanks for shearing this blog.
ReplyDeleteHow to Print From iPad to Wireless Printer
How to print from iPhone to HP printer without Airprint?
How to Print From iPhone To Canon Printer
Why my Wireless Printer not Answering Back
What to do When my Printer Stop Responding to my Computer
Learn to Connect your Printer & the Computer via USB Cable?
Learn to Connect your Printer to the Computer via Wireless Setup Wizard
How to Setup HP Printer to Print from iPhone
How to Fix Brother Printer Drum Error At Your Own
As an assignment helper, we know that assignment writing is the most important task for every student. The role of assignment writing in life and process is important for evaluating a student's skills and abilities, so if you are looking for assignment help UK, make the right decision and go for the best organization in the United Kingdom, GlobalAssignmentExpert is popular for my assignment help online, with us you can get all the necessary services at a pocket-friendly price. We satisfied all our customers with our quality services for global assignment.
ReplyDeletegta vice city free download for pc is the best game of 2021
ReplyDeleteA switch bit is a cutting device utilized with a switch to defeat out (or burrow out) spaces in the outside of a by and large hard workpiece. In spite of the fact that switches and switch pieces are all the more generally utilized in carpentry applications like cabinetry and carpentry, these cutting apparatuses can likewise act in metals, plastics and different materials.router ip
ReplyDeleteHi
ReplyDeleteThanku so much for providing wonderful information,Ozpaperhelp.com is the best platform where
you can get the best information about your assignment and Thesis
System Science Engineering Assignment Help Uk
System Science Engineering Assignment Help Uk
STATISTICAL MODELLING ASSIGNMENT
Programming
Performance Management For HR
Accounting Information Systems
HI6008 Assignment 1
Multisim Assignment Help
Mechanical Engineering Assignment Help
Civil Engineering Assignment Help
Environmental Engineering Assignment Help
Data Warehouse Assignment Help
Information Technology Assignment Help
Technology Assignment Help
Information Systems Business Assignment Help Uk
Networking Technologies Assignment Help
DATA COMMUNICATION AND NETWORK
If yes, ARC Welder can be your best choice. arc welder can run Android Apps and Games on Windows computers.
ReplyDeletelatest release ringtone download free for you mobile ijn mp3 formates
ReplyDeletexender apk download thye one of the best file sharing application
ReplyDelete
ReplyDeleteIf your carrier allows it, you can view your APN settings in one of the following locations: Settings > Cellular > Cellular Data Options > Cellular Network. Settings > Mobile Data > Mobile Data Options > Mobile Data Network
wom chile apn settings
movistar chile apn settings
entel chile apn settings
telcel mexico 4g lte apn settings
koodo apn settings canada
fido apn settings 4g canada
chatr apn settings 4g Canada
rogers apn settings 4g
aldi mobile apn settings australia
vodafone 4g apn settings australia
lycamobile apn settings 4g high speed
optus apn settings
telstra apn settings 5g australia
jio 4g apn settings
vi vodafone idea apn settings
apn settings for airtel
CheapAssignmentHelp.co.uk is the World’s Best Online Assignment help, Academic Homework Help and writing assistance web provider that prides itself in being the best online assignment help website for students around the world.
ReplyDeleteHelp With Microeconomics Assignment
Research Paper Writing Service
Cheap Research Papers Assignment Help
Psychology Assignment Writing Help
Online Psychology Assignment Help Australia
Philosophy Assignment Help
Information System Assignment Help
UML Assignment Help
Unit 24 Destination Management Services
Unit 22 Airport Operations Management
Unit 21 Airline Operations Management
Unit 11 Corporate Travel Management
Unit 8 Visitor Attraction Management
Unit 7 Managing Conference and Events
Unit 38 Operations Management Support
International Trade Assignment Help
Burns Wound Management
Project Management Assignment Solutions
Business Management Assignment
Brand Management Assignments Help
Global Operations Management Assignment Help
LD6034 -Web Programming Assignment Help
Sole Parenting
Academic Integrity Statement Assignment Help
Amazing Blog, keep it up for more valuable like this. Visit OGEN Infosystem for Top SEO Agency, Content Writing Agency, Digital Marketing Agency, PPC Agency in Delhi in affordable price at Digitaginfo.
ReplyDeleteSEO Agency in Delhi
Mind blowing Article.Thanks for the remarkable information. Please keep updating us.
ReplyDeleteWebsite Designing Company in Meerut
Website Designing Company in Delhi
best hoarding company in india
News Today
best magazine in india
ReplyDeleteरक्षा बन्धन
रक्षाबंधन कब है
रक्षाबंधन कितने तारीख को है
रक्षाबन्धन
pmjaycsc
mera kya naam hai
मेरा नाम क्या है
गूगल मेरा नाम क्या है
google mera naam kya hai
dream11 login
many many happy returns of the day in hindi
wish you many more happy returns of the day
jio tv
I am happy with your high quality and well researched content service and recommend carrying on such applauding post. Also, check oou cut off mark for pharmacy
ReplyDeleteThis is a very useful and important information, it was so useful to me and other readers, thank you for always feeding the readers with interesting and useful information, your blog is indeed doing very well, weldone, meanwhile you can checkout what is futo post utme form out
ReplyDeleteKeep your devices connected in every room. NETGEAR WiFi range extenders help you keep mobile devices, media players and computers connected to WiFi with a fast, reliable connection and expanded coverage in every corner of your home.mmywifiext.net login
ReplyDeleteTrusted Android App Developer in Meerut
ReplyDeleteAre you planning to create an application for your business and looking for an Android App Developer in Meerut? Grab the opportunity to get a discount on Android application Services in Meerut. Get to know Sandeep Sharma a leading and a renowned android app developer located in Meerut and working at Techdost Services Private Limited!
Sandeep Sharma is an organised, trustworthy and reliable Android app developer in Meerut, providing high-quality and cost-effective Android app development services in Delhi and all over India.
Android app developer in Meerut
There is an easy to identity your router's IP address. You can use router admin address 192.168.0.1 or 192.168.0.1 to enter into the setting area. You can also the guide on jiofi.local.html here.
ReplyDeleteWho can Do My Assignment Online? Myassignmentexperts is a top Assignment Help website in Canada
ReplyDelete. They offer online Assignment Assistance Canada and Homework Assistance Canada Service with a low cost Assignment Maker.
Very well-written article, thank you for the valuable and useful information you provide in this post. nigerian navy past questions and answers pdf
ReplyDeleteThey supply an immediate signup bonus of 20 free spins as quickly as you open your account. Then if you make your first deposit, they offer a one hundred pc up to as} 1 BTC match deposit bonus. The game has medium variance, 5×3 grid, and a complete of 20 paylines. You can bet as little as $0.2 per spin, go as high as $100 for a maximum win of 1,056x the stake. We’ve taken a unique strategy to the '12 Days of Christmas' providing you with 12 slot games packed with... Slots may be the most vibrant and thrilling games at 카지노사이트 casinos on-line.
ReplyDeleteThank you for the great information. check yobe state university postgraduate application deadline
ReplyDelete