These are chat archives for AngularClass/NG6-starter

6th
Oct 2015
Roman Storm
@rstormsf
Oct 06 2015 21:14 UTC
how do I define model in NG6starter?
Sergey Protko
@fesor
Oct 06 2015 21:15 UTC
well… model is something that is decoupled from framework. In case of angular, models are services which works with your data.
Andy Brown
@brownish
Oct 06 2015 21:16 UTC
Generally you'd define your model on the backend
And then again on the frontend
in a service or you could do it in a controller
Sergey Protko
@fesor
Oct 06 2015 21:17 UTC
you could but please don’t )
Andy Brown
@brownish
Oct 06 2015 21:17 UTC
yeah lol
Sergey Protko
@fesor
Oct 06 2015 21:18 UTC
also, do you mean buisness objects or models? Frontend more often has very thin dmain layer
Roman Storm
@rstormsf
Oct 06 2015 21:18 UTC
ok, how to enable 2 way biding in ng6starter?
like I want <button ng-disabled="SOMESCOPEPROP" id="join-room" ng-click="vm.joinRoom()">Join Room</button>
Sergey Protko
@fesor
Oct 06 2015 21:19 UTC
please read angular documentation
Roman Storm
@rstormsf
Oct 06 2015 21:19 UTC
yeah, it uses $scope
Sergey Protko
@fesor
Oct 06 2015 21:19 UTC
nope
Andy Brown
@brownish
Oct 06 2015 21:19 UTC
you'd have to do ng-disabled="vm.SOMESCOPEPROP"
you should look up the "controllerAs syntax"
Sergey Protko
@fesor
Oct 06 2015 21:19 UTC
vm is property of $scope handled by Angular
Roman Storm
@rstormsf
Oct 06 2015 21:20 UTC
Ohhh
ok
Sergey Protko
@fesor
Oct 06 2015 21:20 UTC
this is alias for you controller
Roman Storm
@rstormsf
Oct 06 2015 21:20 UTC
thank you
Sergey Protko
@fesor
Oct 06 2015 21:20 UTC
please note that in angular2 there is no 2way binding.
Andy Brown
@brownish
Oct 06 2015 21:21 UTC
I need to do some more reading on angular2...
Roman Storm
@rstormsf
Oct 06 2015 21:21 UTC
Me too
Sergey Protko
@fesor
Oct 06 2015 21:21 UTC
I hightly recommend you not to rely on it to match)
Andy Brown
@brownish
Oct 06 2015 21:21 UTC
is it close to production ready?
Sergey Protko
@fesor
Oct 06 2015 21:21 UTC
no… (
Andy Brown
@brownish
Oct 06 2015 21:21 UTC
:/
Sergey Protko
@fesor
Oct 06 2015 21:21 UTC
I hope to see something usable in next few months
Andy Brown
@brownish
Oct 06 2015 21:21 UTC
that would be awesome
Sergey Protko
@fesor
Oct 06 2015 21:22 UTC
instead of 2way binding you could use combination of ng-model + ng-change
this is how it would work in angular2
in this case ng-model will set view value (one-way binding) and ng-change will fire new model value
Andy Brown
@brownish
Oct 06 2015 21:22 UTC
ahh
Sergey Protko
@fesor
Oct 06 2015 21:22 UTC
but… maybe it too soon for you)
Andy Brown
@brownish
Oct 06 2015 21:23 UTC
yeah, I'd rather wait to implement it
i've been abstracting most things like table views and such to directives
Sergey Protko
@fesor
Oct 06 2015 21:23 UTC
I hate table view))
Andy Brown
@brownish
Oct 06 2015 21:23 UTC
then passing a config object around my app to help out with api calls and such
yeah same lol
Roman Storm
@rstormsf
Oct 06 2015 21:26 UTC
so if I want to handle button state for each button, I should have 3 properties on controller for each button?
<button id="open-room" ng-click="vm.openRoom()" ng-disabled="vm.isDisabled" >Open Room</button>
    <button ng-disabled="vm.isDisabled" id="join-room" ng-click="vm.joinRoom()">Join Room</button>
    <button id="open-or-join-room" ng-click="vm.openOrJoin()" ng-disabled="vm.isDisabled">Auto Open Or Join Room</button>
right now if I button is clicked = all of them will set state to Disabled
what is good way to stay DRY
Andy Brown
@brownish
Oct 06 2015 21:27 UTC
i would just have three buttons and use ng-hide or ng-if
but that's probably the easy way out
Roman Storm
@rstormsf
Oct 06 2015 21:27 UTC
i don't want to hide them
just switched to be disabled
once clicked
Sergey Protko
@fesor
Oct 06 2015 21:28 UTC
yes, you see other options?
Andy Brown
@brownish
Oct 06 2015 21:28 UTC
oh
then add something in your vm.joinRoom function that sets vm.isDisabled to true
maybe have each button have its own vm.isBUTTONNAMEDisabled value
Roman Storm
@rstormsf
Oct 06 2015 21:28 UTC
ok, so isDisabledBtn1, isDisabledBtn2, isDisabledBtn3
Andy Brown
@brownish
Oct 06 2015 21:28 UTC
yeah
Roman Storm
@rstormsf
Oct 06 2015 21:29 UTC
:-( ok
Andy Brown
@brownish
Oct 06 2015 21:29 UTC
then after they have successfully joined the room you can set that disabled value to true
that seems to be the easiest
Sergey Protko
@fesor
Oct 06 2015 21:29 UTC
well… i use something like… isSomethingAllowed instead of isDisabledBtn

what is good way to stay DRY

DRY is more about reducing duplication of buisness logic, single source of truth.

in your case there is no duplication since this is independent buttons