Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
[object Object] is automatically appeared as value in every textbox in my form. May i know what went wrong? It appears after i inserted the attribute name="searchr" in tag. Thanks.
in search.htm:
<form ng-submit="search()" ng-controller="formcontrol" name="searchr">
<input type="search" placeholder="Search here" id="text_search" ng-model="searchr.text" name="text">
in controller.js:
.controller('SearchCtrl', function($scope, $http) { }
<form name="searchr">
This creates an object of type FormController, and stores it into the scope under the name searchr.
<input name="text">
This creates an object of type NgModelController and stores it in the FormController's text attribute.
<input ng-model="searchr.text">
This tells angular that the model of the field (i.e. the text that must be displayed in the field) is searchr.text, but due to the above, searchr.textis the NgModelController object created by angular, which is part of the FormController object created by angular.
Don't use the same name for the form as the name you use to store the model of the form.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
How to store fa-icons values in checkbox in MySQL using CodeIgniter.
<form method="post" action="/action_page.php">
<div>
<input type="checkbox" id="fa-icon" name="icon" value="cat">
</div>
<div>
<button type="submit">submitt</button>
</div>
</form>
In this example, we've got a name of icon, and a value of cat. When the form is submitted, the data name/value pair will be icon=cat.
If the value attribute was omitted, the default value for the checkbox is on , so the submitted data in that case would be animal=on.
<i class="icon-<?= $this->input->post('icon'); ?>"></i> <img src="cat-<?= $this->input->post('icon'); ?>.jpg" height="42" width="42">
will give you "cat -image or cat-icon"
By using name attribute
The name attribute specifies the name of an element. The name attribute is used to reference elements in a JavaScript, or to reference form data after a form is submitted. Note: Only form elements with a name attribute will have their values passed when submitting a form.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have a text field on which i have used max checked of angular js.
its working absolutely fine but i want to show error in span if text.length reached the max length. like ng-if searchtext.length== max show a message
<form name="myForm">
<input
type="text"
name="myText"
ng-model="myModel"
ng-maxlength="2">
<span ng-show="myForm.myText.$error.maxlength">Error</span>
</form>
using the Angular documentation : maxlength
https://docs.angularjs.org/api/ng/directive/ngMaxlength
Example should be fine for you I hope
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Below I have function called setProject() inside this function I have to send Id but value is not binding.
<tr ng-repeat="Project in Projects">
<td>
<div>
<input type="radio" ng-click="setProject({{Project.Id}})"/> {{Project.Nm}}
</div>
</td>
</tr>
When using ng-click you don't need to interpolate { }:
Change this:
ng-click="setProject({{Project.Id}})"
To this:
ng-click="setProject(Project.Id)"
The ng-click directive is already away of the Angular context in this case. It takes an Angular Expression as input.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have an array like var names=["price","quality","service"], I have to convert that array to object like names=[{"name":"price", "value":"1.3"},{"name":"quality","value":"3"},{"name":"service","value":"3.4"}]. Each and every time array values are different. I need to do build the input field with that values by using ng-repeat like
<div ng-repeat="n in names">
<input name="rating" ng-model="n" value="0"/>
</div>
How I can fetch the values as objects when user submits the form. can any one help me.
Update
I need json as like this:::
names=[{"name":"price", "value":"1.3"},{"name":"quality","value":"3"},{"name":"service","value":"3.4"}]
ThanQ!
Declare you model object
$scope.item={};
Then just do
<div ng-repeat="n in names">
<input name="rating" ng-model="item[n]" value="0"/>
</div>
The data will be collected into item object.
Update: To get such in such a model, we would have to create it before binding it to view. Assuming names has all the items in the controller do:
var items=names.map(function(name){ return { name:name,value:null}; })
This creates an array of the format you require.
Now bind the view to:
<div ng-repeat="item in items">
<input name="rating" ng-model="item.value" value="0"/>
</div>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Example problem http://plnkr.co/edit/nqgujfj7msKoJ4Tm3Tlz?p=preview
The universal loade xls files
steps:
load xls file
set select value according to col data and again load
Why , on second step function changeSelect return undefined, or how on second step get value all select's user-selected!?
Short answer: You are asking for $scope.myOpt from a scope that is an ancestor of the scope that actually contains myOpt.
Long answer: This code:
<body ng-controller="MainCtrl">
...
<tr ng-repeat="row in rows">
<td ng-repeat="cell in row">
<select ng-change="changeSelect();" ng-model="myOpt" ng-options="..."></select>
Creates the following scope hierarchy:
$rootScope
MainCtrl scope <- myOpt is read here
1st ng-repeat scope
2nd ng-repeat scope <- myOpt is set here
According to JS prototypical inheritance, the ancestor scope cannot see the variable.
For your case I'd suggest passing myOpt to the changeSelect():
<select ng-change="changeSelect(myOpt)" ng-model="myOpt" ng-options="..."></select>
And:
$scope.changeSelect = function(x) {
console.log(x); // or whatever
};