--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en.
Well, that's the thing... I'm not submitting the form. I'm using a button click to call a method on the controller, which in turn would be doing a POST. The thing is, my POST data has to be in JSON, and I have yet to figure out how to get Angular to output JSON without a bunch of garbage in it (see this topic:https://groups.google.com/forum/?fromgroups#!topic/angular/gjoA-7Ivhfs).
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en.
You misunderstand, I know it's acceptable to put a pre selected item in html. But I'm talking about in angular which is a different thing entirely.
Let's say you bind a select to a model and have option C with a selected attribute. Let's also say you have that same model set to option B in your JavaScript controller. Which one should take precedence when the page loads? Now let's imagine you load in a partial with another select on the same model set to option D, what should happen then? Keep in mind these are defaults. Find loading more html really change model values?
I'm not the core team, but I believe they choose to ignore all html default values for the sake of sanity, and not just on select elements. My thought would be you would find yourself running around trying to find the code that is randomly changing the value of your JavaScript variable for quite a while before you realize your designer negligently set the selected attribute, or if you have multiple references to the same model.
If you don't use ngmodel then of course you don't run into this problem altogether. But you are trying to mix angular with non angular. Why parse the form if you can just grab the model variable.
I didn't see a fiddle link anywhere but my suggestion is to digress a step. Explain what your ultimate end goal is, perhaps you are going about it wrong? I can try to help if I knew why you cared about inline defaults. Are you using native form posting behavior? Do you not have access to the JavaScript?
--
You misunderstand,
I know it's acceptable to put a pre selected item in html. But I'm talking about in angular which is a different thing entirely.
Let's say you bind a select to a model and have option C with a selected attribute. Let's also say you have that same model set to option B in your JavaScript controller. Which one should take precedence when the page loads? Now let's imagine you load in a partial with another select on the same model set to option D, what should happen then? Keep in mind these are defaults. Find loading more html really change model values?
I'm not the core team, but I believe they choose to ignore all html default values for the sake of sanity, and not just on select elements. My thought would be you would find yourself running around trying to find the code that is randomly changing the value of your JavaScript variable for quite a while before you realize your designer negligently set the selected attribute, or if you have multiple references to the same model.
If you don't use ngmodel then of course you don't run into this problem altogether. But you are trying to mix angular with non angular. Why parse the form if you can just grab the model variable.
I didn't see a fiddle link anywhere but my suggestion is to digress a step. Explain what your ultimate end goal is, perhaps you are going about it wrong? I can try to help if I knew why you cared about inline defaults. Are you using native form posting behavior? Do you not have access to the JavaScript?
On Wednesday, August 8, 2012 9:59:50 AM UTC-7, ProLoser wrote:You misunderstand,
This would probably be the case with most things that I am trying to do with Angular. I do appreciate the detailed explanation, though. It does help me as I to try to understand things.I know it's acceptable to put a pre selected item in html. But I'm talking about in angular which is a different thing entirely.
As I am finding out! It really is appearing that Angular is much like the .Net platform in that respect. It either handles everything or you have a hell of a time with work-arounds.
Let's say you bind a select to a model and have option C with a selected attribute. Let's also say you have that same model set to option B in your JavaScript controller. Which one should take precedence when the page loads? Now let's imagine you load in a partial with another select on the same model set to option D, what should happen then? Keep in mind these are defaults. Find loading more html really change model values?
In any of those cases, I believe that Angular should be checking for default values and respecting them instead of just blindly over-writing them. Even .Net does this.
I'm not the core team, but I believe they choose to ignore all html default values for the sake of sanity, and not just on select elements. My thought would be you would find yourself running around trying to find the code that is randomly changing the value of your JavaScript variable for quite a while before you realize your designer negligently set the selected attribute, or if you have multiple references to the same model.
I don't concur. Instead of a process of elimination (usually the longest way to determine something,) the better course is to look at where un-wanted change is being noticed and then see if the options all point to this area. If you, as the developer, expect the selected option to be X and you see that it isn't, your first place to check the problem should be to look at the HTML source (which is, after all, what the browser begins the render based upon) and see if there is a reason there. While I am new to unit testing, I believe that test results that indicate that your scripts were correct would also lead you to look at the HTML to see what was going on. I could be wrong, though.
If you don't use ngmodel then of course you don't run into this problem altogether. But you are trying to mix angular with non angular. Why parse the form if you can just grab the model variable.
Well, to solve the problem I did exactly that: removed the ng-model and parsed the form with a simple jQuery routine. I'm not having any luck getting the ng-model data to be available to my controller methods, which is probably the source of the problem. I follow the examples and it just isn't translating.
I didn't see a fiddle link anywhere but my suggestion is to digress a step. Explain what your ultimate end goal is, perhaps you are going about it wrong? I can try to help if I knew why you cared about inline defaults. Are you using native form posting behavior? Do you not have access to the JavaScript?
Ok, here goes:We have a form that is used to enter new customers. Certain defaults are set so that the average user only needs to type in the first and last name at the very least before saving and moving on. These defaults are contained in dropdowns. Just because the dropdowns have pre-selected items doesn't mean that the others can't be chosen. For example<select name="customer_type" id="customer_type"><option value="0">Local</option><option value="1" selected="selected">Regional</option><option value="2">National</option></select>The majority of new customers are "Regional" but now and then one of the others comes in. Having that value pre-selected makes sense and speeds up the process. All we need Angular to do is parse the data from the form and ship it out to a remote service. Data NEVER gets populated back to this form, so there is no real need for data-binding. We tried putting the ng-model into the form to simplify the parsing, but all it did was convolute things. The simple solution was to use jQuery to grab the form data, put it into JSON, and then pass it to Angular for sending it out to the remote service. The form is not using native post behavior. Rather, a button click calls a method on an Angular controller the does the parsing, xhr, and then redirection via Angular routing, and that part works great.I have access to all of the JavaScript (I'm the guy writing it) but much of it can't be posted for privacy reasons. Thank you very much for your efforts.
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en.
Alex: I'm sorry, but that code looks... ugly. I mean putting business logic so tightly laced into your HTML. I'd prefer doing it in the controller. Your example would require that if-statement check on each and every option. Or lets say you only have it on one option, why have that logic in your HTML? You could alternatively use ng-repeat (although this behaves strangely on <options>) but at least you'd only write the check once. I honestly think it's cleaner to do it in the controller for such a specific check.
Michael: responses inlineOn Wed, Aug 8, 2012 at 11:57 AM, Michael Bielski <michael...@yahoo.com> wrote:
On Wednesday, August 8, 2012 9:59:50 AM UTC-7, ProLoser wrote:You misunderstand,
This would probably be the case with most things that I am trying to do with Angular. I do appreciate the detailed explanation, though. It does help me as I to try to understand things.I know it's acceptable to put a pre selected item in html. But I'm talking about in angular which is a different thing entirely.
As I am finding out! It really is appearing that Angular is much like the .Net platform in that respect. It either handles everything or you have a hell of a time with work-arounds.
Let's say you bind a select to a model and have option C with a selected attribute. Let's also say you have that same model set to option B in your JavaScript controller. Which one should take precedence when the page loads? Now let's imagine you load in a partial with another select on the same model set to option D, what should happen then? Keep in mind these are defaults. Find loading more html really change model values?
In any of those cases, I believe that Angular should be checking for default values and respecting them instead of just blindly over-writing them. Even .Net does this.What if 2 inputs on the page are binded to the same model but have different defaults? What do we do then? Does .Net even bother with the JS? That last question is just my own lack of knowledge.
Why are you comparing this to .Net? I don't know how often people feel .Net is 'the best approach'. And the previous comment didn't seem to think so either. I've worked with .Net and was frustrated by the lack of control I had over the view layer. You're also not locked into angular. You just chose to use the ngModel directive, and this is how it works. Don't use ngModel on the input/select and you're shiny.
I'm not the core team, but I believe they choose to ignore all html default values for the sake of sanity, and not just on select elements. My thought would be you would find yourself running around trying to find the code that is randomly changing the value of your JavaScript variable for quite a while before you realize your designer negligently set the selected attribute, or if you have multiple references to the same model.
I don't concur. Instead of a process of elimination (usually the longest way to determine something,) the better course is to look at where un-wanted change is being noticed and then see if the options all point to this area. If you, as the developer, expect the selected option to be X and you see that it isn't, your first place to check the problem should be to look at the HTML source (which is, after all, what the browser begins the render based upon) and see if there is a reason there. While I am new to unit testing, I believe that test results that indicate that your scripts were correct would also lead you to look at the HTML to see what was going on. I could be wrong, though.You're going about things with the idea that it's all about DOM. AngularJS requires a mentality that your JS should stand alone from the DOM. Let me reiterate: Your JS should NOT rely on your HTML. That's too tightly coupled and defeats one of the main intentions of Angular; standalone testability.
Fine, if you're building HTML and JS very closely together, you may check the DOM first. But as I said, if you have 100s of inputs generated on the page all attached to the same model, that could make things difficult and complex. Compare this to setting model defaults upon controller initialization.
If you don't use ngmodel then of course you don't run into this problem altogether. But you are trying to mix angular with non angular. Why parse the form if you can just grab the model variable.
Well, to solve the problem I did exactly that: removed the ng-model and parsed the form with a simple jQuery routine. I'm not having any luck getting the ng-model data to be available to my controller methods, which is probably the source of the problem. I follow the examples and it just isn't translating.
I didn't see a fiddle link anywhere but my suggestion is to digress a step. Explain what your ultimate end goal is, perhaps you are going about it wrong? I can try to help if I knew why you cared about inline defaults. Are you using native form posting behavior? Do you not have access to the JavaScript?
Ok, here goes:We have a form that is used to enter new customers. Certain defaults are set so that the average user only needs to type in the first and last name at the very least before saving and moving on. These defaults are contained in dropdowns. Just because the dropdowns have pre-selected items doesn't mean that the others can't be chosen. For example<select name="customer_type" id="customer_type"><option value="0">Local</option><option value="1" selected="selected">Regional</option><option value="2">National</option></select>The majority of new customers are "Regional" but now and then one of the others comes in. Having that value pre-selected makes sense and speeds up the process. All we need Angular to do is parse the data from the form and ship it out to a remote service. Data NEVER gets populated back to this form, so there is no real need for data-binding. We tried putting the ng-model into the form to simplify the parsing, but all it did was convolute things. The simple solution was to use jQuery to grab the form data, put it into JSON, and then pass it to Angular for sending it out to the remote service. The form is not using native post behavior. Rather, a button click calls a method on an Angular controller the does the parsing, xhr, and then redirection via Angular routing, and that part works great.I have access to all of the JavaScript (I'm the guy writing it) but much of it can't be posted for privacy reasons. Thank you very much for your efforts.So I'm a little surprised this confuses people, but my coworker had a nearly identical problem. With no code to look at, perhaps this example may point you in the right direction: http://plunker.no.de/edit/BDNaZs?live=previewNote how all defaults are kept together in one place, and declared when the containing object is declared? Note how we don't have to modify the data at all because it's already in the structure the backend is expecting.I prefer this approach whole-heartedly because I find it WAY easier and cleaner than serializing, mapping, formatting, etc. AND the $scope.data is updated in real time, making it ridiculously easy to allow change of values to affect other parts of the page OR to allow other parts of the page to affect the form inputs.
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en.
It's not poor design to have 2 inputs binded to the same model. There have been a few useful times this has come up for me, and I don't see the problem. For instance, what if you have 2 divs and only one is ever shown at a time? By default, HTML doesn't encounter this issue because HTML doesn't share values. Actually... that's not true, if 2 inputs have a name on the form, when you hit submit the last input on the page takes precedent. But then, the last input on the page's default could potentially override the previous input's value.The reason this ISNT bad design in angular is because editing the value of 1 input updates the value for the other, so they are kept in sync (even if you can't see the other input). This is part of why setting the default in 1 place (in the controller) is safer than setting it in the html.That's the ultimate reason why you can't use standard HTML mentality. You don't bind data to inputs in native HTML.
You're doing it wrong.Set the model's default value in the controller, NOT in the HTML. Imagine what would happen if your HTML has the ability to clobber or change your javascript variables upon init.Again, you can avoid a blank option by simply doing $scope.mySelect = 'someValue';
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en.
Yeah, I looked at that but didn't try it. Ah well, hindsight and all. I'll try to remember my IRC account and login... been a few years since I was there. Not even sure if this office will let me go there, but I'll find out. Thanks again!
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en.
You are doing it wrong.
Set the selected item in the controller, not the html.
--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/YX3_JDVGoqo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.