These are chat archives for angular/angular.js

4th
Jan 2017
BiancaPiper
@MissLouisePiper
Jan 04 2017 00:49
hi everyone. is there someone who knows or expert in Laravel framework? can you refer to me someone who is really good at this framework. I badly needed help. i hope you can help me. Thank you
Phuong Nguyen
@neunygph
Jan 04 2017 06:40
Hi everyone
Does anyone know a good image lazyload library other than the one from https://www.appelsiini.net/projects/lazyload ?
Frederik Prijck
@frederikprijck
Jan 04 2017 07:06
@CodeLiftSleep @aventic It's generally a better idea to use controllers for this I'd say. (if I correctly understand what you want to do)
Have a parent controller, exposing the neccesary images.
And a child controller, requiring the parent controller and able to access the images on the parent.
Frederik Prijck
@frederikprijck
Jan 04 2017 07:14
There might be some DOM reading involved. But I wouldn't read the HTML elements from Component 1 by querying the DOM inside Component 2.
Frederik Prijck
@frederikprijck
Jan 04 2017 07:24
If you don't know what I'm talking about, it's comparable to how tab directives communicate in most online samples, see the docs: https://docs.angularjs.org/guide/directive part: Creating Directives that Communicate
Or https://docs.angularjs.org/guide/component part: Intercomponent Communication
Chris
@chris-eaton
Jan 04 2017 09:08
Hey guys.. could someone assist me please.. Ive just migrated from 1.5.X to 1.6.X... One of my directives takes advantage of preAssignBindings (i..e I do things with bindings in the controller constructor) but all the literature regarding this only seems to apply to components i.e. move this logic into the $onInit method. This doesnt get called on a directive controller.. .What should I do in this case?
George Kalpakas
@gkalpak
Jan 04 2017 09:11
@chris-eaton: $onInit() (and all other lifecycle hooks) apply to directives too. The compiler does not distinguish between directives and components (in fact, .component() calls .directive() under the hood). So, $onInit() is the way to go here too.
Chris
@chris-eaton
Jan 04 2017 09:13
Thanks.. Thats what I originally thought.. except its not working! my Controller is invoked, the constructor is called.. but the $onInit method ive made never gets ran?
AHH.. Hang on.. I bet because its throwing an exception in the constructor it never gets round to invoking the $onInit... bear with me ill test
There we go, you were right, I wrongly assumed the $onInit would be called regardless... Thanks!
Frederik Prijck
@frederikprijck
Jan 04 2017 09:54
Upgrading a project from 1.5.9 to 1.6.1 fails silently.
Application starts up, no error
George Kalpakas
@gkalpak
Jan 04 2017 10:30
Disabled preAssignBindings is a common culprit.
How exactly does it fail?
Frederik Prijck
@frederikprijck
Jan 04 2017 10:35
I got it working
It's due to the hashbang change. ('!', Changing the default $location hash-prefix to '!', as the previous empty string default was unconventional and confusing.)
I'm happy I didn't need the preAssignBindings disabled, all's already in the oninit :D
Frederik Prijck
@frederikprijck
Jan 04 2017 10:41
@gkalpak It wasn't failing tho. My browser remembered my url being: http://localhost:3000/#/app
Opening that URL points me to a blank page. No console error.
Using $locationProvider.hashPrefix(''); did the trick.
George Kalpakas
@gkalpak
Jan 04 2017 10:57
Yeah. This is the other usual suspect :smiley:
These changes are also highlighted in the Migration Guide (good stuff :stuck_out_tongue:).

Opening that URL points me to a blank page. No console error.

Why would there be any error? You just navigated to a valid URL (it just so happens that Angular doesn't know anything about it :wink:)

Frederik Prijck
@frederikprijck
Jan 04 2017 11:14
Yep correct :D
But I didn't know the hashbang changed when I said that :P
Alex
@sashberd
Jan 04 2017 11:20
Hey guys. I broke my head with problem that I opened here http://stackoverflow.com/questions/41446230/controller-scope-in-directive-is-not-updated.
Can any body help with it?
Frederik Prijck
@frederikprijck
Jan 04 2017 11:21
You want your head to be fixed ?
Or the problem to be solved ?
Alex
@sashberd
Jan 04 2017 11:21
Both dude :smile:
Frederik Prijck
@frederikprijck
Jan 04 2017 11:22
While looking at the SO, i wonder why you prefix stuff with $
Decade
@decadef20
Jan 04 2017 11:22
wrote too much PHP codes?
Alex
@sashberd
Jan 04 2017 11:23
I was in jquery dev team at least 3 years, a habit
Frederik Prijck
@frederikprijck
Jan 04 2017 11:24
Then drop it.
The SO question is abit chaotic tbh.
Unsure why you post the templatecache to show the template.
Alex
@sashberd
Jan 04 2017 11:24
Some one in comments ask me to show template
Frederik Prijck
@frederikprijck
Jan 04 2017 11:25
The template yes.
But one should not manually put it's template in the template cache imho.
Alex
@sashberd
Jan 04 2017 11:29
Agree, you can edit the question if you like it and earn some points in SO. I was exhausted from this problem, thus sorry for question format and layout
dev-fullstacktechnology
@dev-fullstacktechnology
Jan 04 2017 11:31
@ use to bind unidirectional so it may possible that your directive execute before controller fill data...
try to use = instead of @...
Frederik Prijck
@frederikprijck
Jan 04 2017 11:32
What do u mean @dev-fullstacktechnology ?
It's a good idea to avoid '='.
Not saying that you should avoid it, but not needing it is better then using it.
dev-fullstacktechnology
@dev-fullstacktechnology
Jan 04 2017 11:33
when u use @ binding the directive will not update scope value even your controller changes....so I guess it create problem..
Decade
@decadef20
Jan 04 2017 11:34
I agree with u @dev-fullstacktechnology
dev-fullstacktechnology
@dev-fullstacktechnology
Jan 04 2017 11:34
try to put $scope.$watch on your varibale and check what it have..
Frederik Prijck
@frederikprijck
Jan 04 2017 11:34
Maybe he should try '<' before trying '='
Alex
@sashberd
Jan 04 2017 11:35
@dev-fullstacktechnology no luck, same problem
Frederik Prijck
@frederikprijck
Jan 04 2017 11:35
@decadef20 and @dev-fullstacktechnology There's no need to set up a two way binding when u dont need it.
@sashberd Mind to create a plunkr ?
dev-fullstacktechnology
@dev-fullstacktechnology
Jan 04 2017 11:36
plunkr will be better..
Frederik Prijck
@frederikprijck
Jan 04 2017 11:37
@dev-fullstacktechnology Anyway, you shouldn't be advising people to use '=' for no reason imo.
dev-fullstacktechnology
@dev-fullstacktechnology
Jan 04 2017 11:37
yah i know..
Frederik Prijck
@frederikprijck
Jan 04 2017 11:37
Alright :D
dev-fullstacktechnology
@dev-fullstacktechnology
Jan 04 2017 11:37
+1
Decade
@decadef20
Jan 04 2017 11:37
+1
Frederik Prijck
@frederikprijck
Jan 04 2017 11:38
I never even use '=' anymore.
@sashberd Apart from the issue, (IMHO) you realy shouldn't be using the $templateCache yourself like the way you are doing.
Alex
@sashberd
Jan 04 2017 11:39
@frederikprijck what is problem with it?
Frederik Prijck
@frederikprijck
Jan 04 2017 11:39
I use it aswell
but not manually.
Unreadably, unmaintainable
Alex
@sashberd
Jan 04 2017 11:40
Do you use it with get from file functionality?
Frederik Prijck
@frederikprijck
Jan 04 2017 11:40
I use it the same way u do.
But I still have a templateUrl for my component and directives
element.html($interpolate(template)($scope));
You're doing this stuff manually ?
Alex
@sashberd
Jan 04 2017 11:42
This is one of the next task in my sprint to move all templates to html`s files and put them in $templatecache via $http.get
Frederik Prijck
@frederikprijck
Jan 04 2017 11:42
lol
no
Are u using grunt/gulp ?
Alex
@sashberd
Jan 04 2017 11:42
grunt
I saw examples with grunt
how to do it with grunt
Frederik Prijck
@frederikprijck
Jan 04 2017 11:42
there are grunt plugins
who read all ur directives
put the templateUrl's in templatecache
and handle all fo that for u.
Alex
@sashberd
Jan 04 2017 11:43
Yeap I saw it, will check it , Thanks for advise
it is not undefined it is empty
Frederik Prijck
@frederikprijck
Jan 04 2017 11:44
Well, can you create a plunkr @sashberd ?
Alex
@sashberd
Jan 04 2017 11:44
while in ctrl it is with some objects in it
Frederik Prijck
@frederikprijck
Jan 04 2017 11:44
I'd be happy to look at it.
Alex
@sashberd
Jan 04 2017 11:44
I`m working on it
Frederik Prijck
@frederikprijck
Jan 04 2017 11:44
Perfect
If you mind, drop the templatecache part for the plunkr :)
saves u time
Decade
@decadef20
Jan 04 2017 11:44
how do u solve it ?
Frederik Prijck
@frederikprijck
Jan 04 2017 11:45
Solve what ?
Decade
@decadef20
Jan 04 2017 11:45
forget it . I saw it wrong
Frederik Prijck
@frederikprijck
Jan 04 2017 11:46
@sashberd The widget gets populated once createIdleTimeWidget is called.
Where are you calling this method ?
As long as you don't call it, it'll be an empty object, as defined on line 1407.
(wtf, line 1407 :joy: )
So add controller.createIdleTimeWidget() to the directive link function. (or are you calling it from somewhere else ?)
Alex
@sashberd
Jan 04 2017 11:57
1.5.9
Frederik Prijck
@frederikprijck
Jan 04 2017 11:57
Alright.
I don't think it matters tho.
But do look at components.
Alex
@sashberd
Jan 04 2017 11:58
@frederikprijck it is 1407 after grunt concatination task.
Frederik Prijck
@frederikprijck
Jan 04 2017 11:59
Ah, that's good :D
How's the plunkr going @sashberd ?
Alex
@sashberd
Jan 04 2017 12:00
working on it. I have to much dependencies, thus I will put them all insde plunker
Frederik Prijck
@frederikprijck
Jan 04 2017 12:00
Why ?
Reproduce the problem using as little code as possible.
Don't add everything just coz you are using it.
Alex
@sashberd
Jan 04 2017 12:36
@frederikprijck FEwwwww, here plunker https://plnkr.co/edit/fPY0R0TQXaqw4N3pzLpc
I put 2 debuggers, one in controler and another in directive, you could see that in the $scope inside directive the widget object is empty
and before invoking directive building there is at least one key with values
after second debugger the code is not running but there are now issues with futher running
Frederik Prijck
@frederikprijck
Jan 04 2017 12:38
jesus
To much code.
Alex
@sashberd
Jan 04 2017 12:39
I know man sorry
Frederik Prijck
@frederikprijck
Jan 04 2017 12:39
So do what I said:
Alex
@sashberd
Jan 04 2017 12:39
U can see only in controll
Frederik Prijck
@frederikprijck
Jan 04 2017 12:39
Reproduce the problem using as little code as possible..
You said you worked for the jQuery core team, you should know how to get support.
Alex
@sashberd
Jan 04 2017 12:39
controller
Frederik Prijck
@frederikprijck
Jan 04 2017 12:39
I got no time to dig through all that stuff.
Even tho I want to, I cant.
If you want to get support, strip it down to the relevant stuff.
Remove templateCahce stuff aswell.
You use templateCache for performance, no one gives anything about performance in a plunkr.
Frederik Prijck
@frederikprijck
Jan 04 2017 12:49
And format your code. Code isn't even aligned, making it even harder for me to understand where functions start and end.
Alex
@sashberd
Jan 04 2017 12:55
@frederikprijck OK, I removed all remotes code and made it via cdn https://plnkr.co/edit/fPY0R0TQXaqw4N3pzLpc?p=preview, hope this one is better , any feedbacks?
@frederikprijck Formatted https://plnkr.co/edit/fPY0R0TQXaqw4N3pzLpc
Frederik Prijck
@frederikprijck
Jan 04 2017 12:58
CDN doesn't remove them from it.
You have a specific problem
stript it down to contain only everything to reproduce the problem.
You didn't put any effort in doing that.
You took ur app and put it in a plunkr.
Stripping it down might even give u a chance to find the issue ur self.
and it gives others an easy way to help
Alex
@sashberd
Jan 04 2017 13:00
OK I will try
Frederik Prijck
@frederikprijck
Jan 04 2017 13:02
Sorry, I don't want to be rude @sashberd
Alex
@sashberd
Jan 04 2017 13:17
@frederikprijck It is OK dude, I understand U, but this exactly my problem and I can not build plunkr differently. I have a dashboard directive that I took from https://github.com/DataTorrent/malhar-angular-dashboard#master and inner dashboard widget directive that you can see inside directive.js in my plunkr. My problem is not in dashboard directive it is working fine (I hope), but with inner widget directive, that I get there non updated controller scope.
Frederik Prijck
@frederikprijck
Jan 04 2017 13:19
Ye well you should be able to make an easier plnkr.
If you're not stripping it, we will have to do it.
And that's not something I got time for.
I see so many irrelevant code in ur plunkr.
Matt Erman
@CodeLiftSleep
Jan 04 2017 13:57
So how far are they going to keep going with new releases for Angular JS? I was reading something on the Angular site that says something is deprecated since 1.5 and will be removed in 1.7...so apparently they are planning to keep going with new releases for a while it seems
Frederik Prijck
@frederikprijck
Jan 04 2017 14:13
Yes
But they will have to stop at 1.99 :joy:
Even version 1.6 did remove deprecated stuff.
Matt Erman
@CodeLiftSleep
Jan 04 2017 14:14
Yeah I think they removed .success and .error in 1.6
Frederik Prijck
@frederikprijck
Jan 04 2017 14:14
Yep.
sarper
@a-computer-lover
Jan 04 2017 18:32
Ekran Resmi 2017-01-04 21.32.13.png
@frederikprijck thk u for compliment
Youssef26
@Youssef26
Jan 04 2017 19:10
hey
I Youssef26 would like to make an inquiry about the AngularJs filter |Date , i keep adding one second each second to my timestamp scope, and in html i have {{variable| date:'medium'}} even though the variable is getting updated, the |filter isnt updating
did i do something wrong or is this just how angular works?
ingenieriadigitalideco
@ingenieriadigitalideco
Jan 04 2017 19:29
Hi! I'm trying to implement facebook analytics in Angular 2 but window.fbAsyncInit does not work on Universal Angular. What I can do?
Frederik Prijck
@frederikprijck
Jan 04 2017 19:51
@a-computer-lover Not sure why you'd want to to fake messages.
But enjoy :)
ingenieriadigitalideco
@ingenieriadigitalideco
Jan 04 2017 19:53
I want to implement facebook analytics but I do not know how to use the FB variable inside a component. Can you help me?
Frederik Prijck
@frederikprijck
Jan 04 2017 19:53
@ingenieriadigitalideco this is angular1.
@Youssef26 create a plunkr...
Dylin Maust
@dylin-maust
Jan 04 2017 19:55
Hey guys.. is there a way to use ng-annotate to annotate dependencies in third party libraries?
Frederik Prijck
@frederikprijck
Jan 04 2017 19:55
It needs a string to annotate @TimeBomb006
If that string is present, sure
Dylin Maust
@dylin-maust
Jan 04 2017 19:58
It's a little confusing to me. I'm easily able to add /* @ngInject */ to my own code but I don't know where I could do so for this library. I import the library: `import from 'library-name;' in my index.js root file. Could I then annotate that library within the same file?
import from 'library-name;'
Frederik Prijck
@frederikprijck
Jan 04 2017 19:59
first of all, why do u want to annotate a 3th party library ?
You shouldn't need to.
Dylin Maust
@dylin-maust
Jan 04 2017 19:59
Yeah that's what I thought. It's breaking my build when minified
Frederik Prijck
@frederikprijck
Jan 04 2017 19:59
what library is it ?
I don't have much experience in forking projects / Git in general so I was just trying to avoid that.. unfortunately have used TFS for the last 5 years
Frederik Prijck
@frederikprijck
Jan 04 2017 20:01
I thought so.
Haha
I use TFS aswell.
Tbh there's 2 options:
1 fork and fix it
2 don't use it.
Dylin Maust
@dylin-maust
Jan 04 2017 20:02
Yeah that's what I was thinking. I was hoping I was mistaken
Looks like I'll be learning Git
Frederik Prijck
@frederikprijck
Jan 04 2017 20:02
well
adding the change might not help u for the coming days/weeks
depening on wha tthe author will do.
is that the only issue with the code ?
Dylin Maust
@dylin-maust
Jan 04 2017 20:03
true
yes
I guess I could take the source code and put it in a local folder
Frederik Prijck
@frederikprijck
Jan 04 2017 20:03
can you verify that it works when u change the code to:
lfNgMdFileinput.run([ '$templateCache', function($templateCache){
and make sure to add the closing bracket
Not sure if that's a great library tho.
Dylin Maust
@dylin-maust
Jan 04 2017 20:04
Ah yes it does work
Yeah there are quite a few issues
Frederik Prijck
@frederikprijck
Jan 04 2017 20:05
easiest for you now is add the change locally
Dylin Maust
@dylin-maust
Jan 04 2017 20:05
I couldn't find many material themed file inputs, which I know isn't hugely important cause I could style it myself
Frederik Prijck
@frederikprijck
Jan 04 2017 20:05
and include it in tfs
somewhere outside node_modules
Dylin Maust
@dylin-maust
Jan 04 2017 20:05
yeah good call
Frederik Prijck
@frederikprijck
Jan 04 2017 20:05
Do you have a small project to reproduce the error ?
Dylin Maust
@dylin-maust
Jan 04 2017 20:05
thanks! not sure I didn't think to explicitly annotate it rather than trying to depend on ng-annotate
James
@Srgjames_twitter
Jan 04 2017 20:06
@toxiable
Scripts may close only the windows that were opened by it.
Dylin Maust
@dylin-maust
Jan 04 2017 20:06
no not really, I'm pretty deep into this one unfortunately. I could probably create a repro after this deadline
Frederik Prijck
@frederikprijck
Jan 04 2017 20:06
Ye well I can do a PR if you want
nvm
I don't like that codebase tbh.
The source code looks like crap :D
Dylin Maust
@dylin-maust
Jan 04 2017 20:07
haha yes it does
one giant file
it works though!
Frederik Prijck
@frederikprijck
Jan 04 2017 20:08
FYI: shuyu/angular-material-fileinput#60
Dylin Maust
@dylin-maust
Jan 04 2017 20:08
Oh wow, not sure how I missed that
Frederik Prijck
@frederikprijck
Jan 04 2017 20:09
Well, even if you didn't miss it... Wouldn't have helped u :P
Dylin Maust
@dylin-maust
Jan 04 2017 20:10
Haha indeed. So on that note, have you used any other libraries that you'd recommend?
Frederik Prijck
@frederikprijck
Jan 04 2017 20:10
for fileinput ?
Dylin Maust
@dylin-maust
Jan 04 2017 20:11
Yeah particularly as an angular directive
Frederik Prijck
@frederikprijck
Jan 04 2017 20:12
Tbh I didn't. :D
Doesn't look like it's hard to create for ur self.
But that repo needs some cleaning.
Dylin Maust
@dylin-maust
Jan 04 2017 20:12
Minimal validation (required, max size, file type accept limitation [e.g. /img]), HTML5 File API, maybe an image preview
Frederik Prijck
@frederikprijck
Jan 04 2017 20:13
Nothing wrong with using it if it works tho ...
And you should get familiar with git.
Dylin Maust
@dylin-maust
Jan 04 2017 20:13
Yeah true.. it only took a few hours to integrate and so far it works well enough
Frederik Prijck
@frederikprijck
Jan 04 2017 20:13
I use TFS at work for 6 years aswell.
GIT > tfs
Dylin Maust
@dylin-maust
Jan 04 2017 20:14
Agreed!
I actually am using Git for this project but all I've had to do was integrate VS Code, click the commit button, and run git push every now and then
The consulting company I work for is unfortunately crazy about TFS and doesn't see the value in Git... -_-
I think management doesn't realize that you can use Git with VSTS for work items and project management
Frederik Prijck
@frederikprijck
Jan 04 2017 20:15
FYI: shuyu/angular-material-fileinput#61
@TimeBomb006 where u from ?
Dylin Maust
@dylin-maust
Jan 04 2017 20:16
Wow thanks a lot
I'm in Pittsburgh, Pennsylvania
Frederik Prijck
@frederikprijck
Jan 04 2017 20:17
Ye well, I got the same. Client I work at is a fan of TFS.
Dylin Maust
@dylin-maust
Jan 04 2017 20:17
Slowly but surely I'll convince them to start new projects with Git instead
In fact, we only recently started with Angular 1.x projects, and the senior devs create Visual Studio projects and use the VS task runner extension
I took it upon myself to learn npm and webpack for this project. It's so much better
Frederik Prijck
@frederikprijck
Jan 04 2017 20:18
I'm forced to use VS aswell. Wasn't allowed for VSC :D
Dylin Maust
@dylin-maust
Jan 04 2017 20:20
I do enjoy it for Web API but I think it's a bit overkill for non-.NET web apps
Frederik Prijck
@frederikprijck
Jan 04 2017 20:20
Yep idd.
Can you check my pm @TimeBomb006
Ayush Bahuguna
@relentless-coder
Jan 04 2017 20:26
I am building a multi step form, but my controller object is not storing data.

i have $scope.newuser = {} in my controller, and I have ng-models as,

ng-model="newuser.firstname"
ng-model="newuser.lastname"
ng-model="newuser.email"

but nothing is getting stored in my newuser object.

@frederikprijck

          <div class="name-wrap">
            <input type="text" ng-model="newuser.firstname" name="firstname" id="firstname" value="" placeholder="First Name">
            <input type="text" ng-model="newuser.lastname" name="lastname" id="lastname" value="" placeholder="Last Name">
          </div>

here's a sample html that I am using.. I have placed a div with {{newuser}} inside it to see the values, but it's not getting stored.

Frederik Prijck
@frederikprijck
Jan 04 2017 20:31
@relentless-coder I need more then that to understad what might be going wrong.
How are you connecting the html to the controller ?
Ayush Bahuguna
@relentless-coder
Jan 04 2017 20:32
I have built this form using Angular UI route, so I have attached the same controlller FormCtrl while configuring the views. I even have controller attached to my index.html which is the base html.
Kurt
@Zaft
Jan 04 2017 20:34
@relentless-coder Try dropping an example in https://plnkr.co/edit/?p=catalogue
Ayush Bahuguna
@relentless-coder
Jan 04 2017 20:35
okay.
Frederik Prijck
@frederikprijck
Jan 04 2017 20:38
@relentless-coder I don't realy understand what you mean with that.
Could you elaborate on so I have attached the same controlller FormCtrl while configuring the views. I even have controller attached to my index.html which is the base html.
or atleast show the code ?
Ayush Bahuguna
@relentless-coder
Jan 04 2017 20:41
https://plnkr.co/edit/1hBM8jOBnGTEbyNfCmKn?p=preview
here is the plunkr, but it is not working on it, maybe filepath issue
Frederik Prijck
@frederikprijck
Jan 04 2017 20:41
Alright, let's start with a simple plunkr @relentless-coder
Ayush Bahuguna
@relentless-coder
Jan 04 2017 20:42
@frederikprijck okay, I have changed the paths to css and js, and now you can see the form
Frederik Prijck
@frederikprijck
Jan 04 2017 20:42
You don't need the ng-controller
Ayush Bahuguna
@relentless-coder
Jan 04 2017 20:42
what?
Frederik Prijck
@frederikprijck
Jan 04 2017 20:43
In your index.html ?
Ayush Bahuguna
@relentless-coder
Jan 04 2017 20:43
yes.
Frederik Prijck
@frederikprijck
Jan 04 2017 20:43
it's working.
Just not the way u think it works.
Controllers are, afaik, not singletons.
Ayush Bahuguna
@relentless-coder
Jan 04 2017 20:45
I didn't get that.
Frederik Prijck
@frederikprijck
Jan 04 2017 20:45
So if you look at the plunkr I linked, and u put some data in the form you will see it get's populated...
Ayush Bahuguna
@relentless-coder
Jan 04 2017 20:46
yes, but why doesn't it work when put inside the index.html ?
Frederik Prijck
@frederikprijck
Jan 04 2017 20:46
A controller is not a singleton.
It's not supposed to work that way.
You have two instances of the same controller
both having their own newuser object
which is not the same in memory.
But again, you should remove that ng-controller in index.html anway.
Ayush Bahuguna
@relentless-coder
Jan 04 2017 20:51
okay one more thing, is their way to store the data. because i think, every time a new view is loaded the old data gets removed. Or should I have different controllers for each view?
Frederik Prijck
@frederikprijck
Jan 04 2017 20:51
Use a service.
A service is a singleton.
So you can share the same instance of a service in different controllers.
So 2 controllers can use the same service and it will be only 1 instance.
So if you have a service with a newuser object, then it will work. :)
But yes, you should have different controllers for each view.
You should look into components, which are basicly a combination of a view and a controller.
Ayush Bahuguna
@relentless-coder
Jan 04 2017 20:53
okay, i need to create a service and create newuser inside it and then use that service in the controller. okay.
@frederikprijck hey can you refer to me some really good courses on Angular js? I need to understand it better.
Frederik Prijck
@frederikprijck
Jan 04 2017 20:57
read the docs for a starter.
If you dont know services, you didnt read the docs.
Ayush Bahuguna
@relentless-coder
Jan 04 2017 21:01
i read, but since it is so much, i think the problem is that until and unless I use a concept I don't get it.
great intro and free set of videos
Ayush Bahuguna
@relentless-coder
Jan 04 2017 21:08
@Zaft hey thanks :)

@frederikprijck

app.factory("data",["$log", function($log){
  var newuser = {};
  var userData = [];
  return function() {
    $log.log(newuser);
    userData.push(newuser);
    newuser = {};
  };
}]);

so, I created a service. and this is how I use it in my controller

app.controller("FormCtrl", ["$scope", "$location", "$window", "data", function($scope, $location, $window, data) {
    $scope.newuser = {};
    $scope.storeData = function() {
      data();
    };
Frederik Prijck
@frederikprijck
Jan 04 2017 21:11
nope @relentless-coder
read the docs.
That's not how you should create a service or factory.
Frederik Prijck
@frederikprijck
Jan 04 2017 21:28
Basicly, @relentless-coder you need to return an object.
return { newUser: {} }
Ayush Bahuguna
@relentless-coder
Jan 04 2017 21:41
okay so i use the factory to return newuser object, then in the controller push that into an array. Official documents are hard for me, I started coding just over 6 months ago. But I will look into it. thank you for your help @frederikprijck
Frederik Prijck
@frederikprijck
Jan 04 2017 21:42
You need this;
app.factory("dataService", function(){
  return {
    newUser: {}  
  }
});
and
Ayush Bahuguna
@relentless-coder
Jan 04 2017 21:43
so, how do I store values to newuser?
Frederik Prijck
@frederikprijck
Jan 04 2017 21:43
app.controller("FormCtrl", ["$scope", "$location", "$window", "dataService", function($scope, $location, $window, dataService) {
    $scope.newuser = dataService.newUser;
});
now u can bind newuser to ur form, the same way u already did.
And the values will be available in dataService.newUser.
Ayush Bahuguna
@relentless-coder
Jan 04 2017 21:44
okay. that makes sense.
Frederik Prijck
@frederikprijck
Jan 04 2017 21:44
Just read the docs, they exist for a reason and are far from hard.
Goodluck! :)
Ayush Bahuguna
@relentless-coder
Jan 04 2017 21:47
well it's the terms that get me. thank you so much. It's 3 in the morning in here, I should sleep. take care :)
Ayush Bahuguna
@relentless-coder
Jan 04 2017 22:01
hey, @frederikprijck you still there? I tried that I am getting an empty object.
Eder Gomez
@Ederagp
Jan 04 2017 23:24
Hi!, How do I place a course focus on an input?