These are chat archives for AngularClass/NG6-starter

6th
Oct 2015
Roman Storm
@rstormsf
Oct 06 2015 21:14
how do I define model in NG6starter?
Sergey Protko
@fesor
Oct 06 2015 21:15
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
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
you could but please don’t )
Andy Brown
@brownish
Oct 06 2015 21:17
yeah lol
Sergey Protko
@fesor
Oct 06 2015 21:18
also, do you mean buisness objects or models? Frontend more often has very thin dmain layer
Roman Storm
@rstormsf
Oct 06 2015 21:18
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
please read angular documentation
Roman Storm
@rstormsf
Oct 06 2015 21:19
yeah, it uses $scope
Sergey Protko
@fesor
Oct 06 2015 21:19
nope
Andy Brown
@brownish
Oct 06 2015 21:19
you'd have to do ng-disabled="vm.SOMESCOPEPROP"
you should look up the "controllerAs syntax"
Sergey Protko
@fesor
Oct 06 2015 21:19
vm is property of $scope handled by Angular
Roman Storm
@rstormsf
Oct 06 2015 21:20
Ohhh
ok
Sergey Protko
@fesor
Oct 06 2015 21:20
this is alias for you controller
Roman Storm
@rstormsf
Oct 06 2015 21:20
thank you
Sergey Protko
@fesor
Oct 06 2015 21:20
please note that in angular2 there is no 2way binding.
Andy Brown
@brownish
Oct 06 2015 21:21
I need to do some more reading on angular2...
Roman Storm
@rstormsf
Oct 06 2015 21:21
Me too
Sergey Protko
@fesor
Oct 06 2015 21:21
I hightly recommend you not to rely on it to match)
Andy Brown
@brownish
Oct 06 2015 21:21
is it close to production ready?
Sergey Protko
@fesor
Oct 06 2015 21:21
no… (
Andy Brown
@brownish
Oct 06 2015 21:21
:/
Sergey Protko
@fesor
Oct 06 2015 21:21
I hope to see something usable in next few months
Andy Brown
@brownish
Oct 06 2015 21:21
that would be awesome
Sergey Protko
@fesor
Oct 06 2015 21:22
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
ahh
Sergey Protko
@fesor
Oct 06 2015 21:22
but… maybe it too soon for you)
Andy Brown
@brownish
Oct 06 2015 21:23
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
I hate table view))
Andy Brown
@brownish
Oct 06 2015 21:23
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
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
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
i don't want to hide them
just switched to be disabled
once clicked
Sergey Protko
@fesor
Oct 06 2015 21:28
yes, you see other options?
Andy Brown
@brownish
Oct 06 2015 21:28
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
ok, so isDisabledBtn1, isDisabledBtn2, isDisabledBtn3
Andy Brown
@brownish
Oct 06 2015 21:28
yeah
Roman Storm
@rstormsf
Oct 06 2015 21:29
:-( ok
Andy Brown
@brownish
Oct 06 2015 21:29
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
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