Angular 2 | Tutorial 9 | ng If Local Variable Assignment | TutorialsPoint [w/ subs]



00:00:00 – so what is going on everybody my name is
00:00:03 – May ho and welcome to your ninth
00:00:06 – tutorial for angular in which I'm going
00:00:09 – to cover what local variable assignment
00:00:12 – is and angular ng if and how you can use
00:00:15 – them right so last time we developed on
00:00:19 – how to use if-else sort of environment
00:00:23 – in angular ng-if let's see how we can
00:00:27 – make use of a local variable or actually
00:00:31 – what does that even mean right so if you
00:00:36 – do something like dave ng if i don't
00:00:43 – know let's just say come to modulus 2 is
00:00:49 – equal to 0 that pretty much means that
00:00:53 – your number which is counter is
00:00:56 – divisible by 2 then I want to show this
00:01:00 – thing so yup
00:01:05 – what we can do is right here red color
00:01:08 – is equal to 0 and what we can do inside
00:01:12 – toggle this is a this dot come through
00:01:18 – flash plus right and now we can do is
00:01:24 – pretty much say let random variable
00:01:32 – write something like that and if I make
00:01:36 – use of this random variable right here
00:01:38 – and see you can see we are dieppe true
00:01:41 – and we get nothing because this
00:01:43 – condition is false and again you have
00:01:46 – true so what's happening here is
00:01:48 – essentially we are getting the result of
00:01:51 – this condition into this thing right so
00:01:56 – what happens if I remove this double
00:01:58 – equal to 0 and save it now you can see
00:02:01 – that if I juggle I get 1 instead of true
00:02:03 – so what what just happened here well
00:02:05 – what we did actually is that with this
00:02:08 – lit random variable we are passing there
00:02:11 – it is
00:02:11 – all of our condition which might not be
00:02:14 – always boolean but you know in
00:02:17 – JavaScript one is evaluated as true and
00:02:20 – if you are ever confused what things
00:02:23 – would be evaluated to what you can just
00:02:25 – go ahead and console and write double
00:02:27 – exclamation and something like or the
00:02:30 – chicken array so it evaluates to true
00:02:31 – and object it also evaluates to true one
00:02:35 – is true zero is false and you can do
00:02:37 – that all day right so one is apparently
00:02:40 – true so we get to see this
00:02:42 – and again fat toggle it you can see that
00:02:44 – it is gone because a condition is not
00:02:46 – false and yeah pretty much there's no
00:02:49 – point in getting a random variable to it
00:02:51 – now you can actually do that with some
00:02:55 – objects as well if you want so you can
00:02:58 – say my favorite languages then object
00:03:03 – and you can say something like content
00:03:07 – is the HTML CSS JavaScript will
00:03:15 – apparently that's the only choice and
00:03:18 – back in we can say no yes PHP Python
00:03:26 – Ruby anything right so yep and where you
00:03:32 – can do is you can go ahead and say ng if
00:03:39 – my favorite line dot front end which is
00:03:44 – obviously an array and as we have seen
00:03:47 – it evaluates to true this falling issue
00:03:51 – here now I can say this is front-end
00:03:55 – languages line twitches now obviously
00:04:00 – you can just go ahead and use something
00:04:04 – like
00:04:06 – this but again it does not guarantee
00:04:10 – that this is not null or this is
00:04:14 – undefined so ng-if is a nice way to
00:04:16 – check if you're working with a very well
00:04:19 – defined variable or maybe it's not fall
00:04:23 – see right so what we can do right now it
00:04:27 – is just a random variable door or
00:04:30 – funding languages start join with a
00:04:33 – comma right simple as that so you can
00:04:36 – see that we get a yep HTML CSS
00:04:38 – JavaScript again we can just toggle it
00:04:42 – but again we have some problems Dorgan
00:04:44 – function doesn't exist so we can just
00:04:46 – get rid of this right now
00:04:47 – right so you can see that this is our
00:04:51 – local variable for this thing only again
00:04:54 – this will not work outside your div you
00:04:57 – can see that we are getting errors so
00:05:00 – this is local to your if conditionally
00:05:02 – and that is how pretty much you make use
00:05:05 – of local variable assignment and angular
00:05:09 – 2 and 4 again whatever you want to call
00:05:12 – this just angular or angular 2 for
00:05:15 – together so yeah that's all for this one
00:05:18 – and if you liked it then don't forget
00:05:19 – subscribe and thank you for watching
00:05:21 – I'll see you then in the next one


Video Url:
http://youtu.be/b1tc5RKT6yg

Comments

comments