# \[SOLVED\] Get "input value" in to controller

**URL:** <https://forum.ionicframework.com/t/solved-get-input-value-in-to-controller/29391>\
**Category:** ionic-v1\
**Created:** [July 28, 2015, 5:22pm UTC](https://forum.ionicframework.com/t/solved-get-input-value-in-to-controller/29391 "2015-07-28T17:22:55Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![coachdesign](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/coachdesign/32/13857_2.png) [@coachdesign](https://forum.ionicframework.com/u/coachdesign)\
**Post date:** [July 28, 2015, 5:22pm UTC](https://forum.ionicframework.com/t/solved-get-input-value-in-to-controller/29391/1 "2015-07-28T17:22:55Z")

</div>

Hi, I need to get into the controller the value of an input field.

```
<script id="tpl/carica.html" type="text/ng-template">
<ion-view view-title="Carica">
	<ion-content class="padding">
		<div class="list list-inset">
			<label class="item item-input">
				<input type="number" id="codice_prodotto" name="codice_prodotto" ng-model="codice_prodotto">
			</label>
		</div>
		<button nav-direction="back" class="button button-block button-large button-balanced" ng-click="carica()">CARICA</button>
	</ion-content>
</ion-view>
</script>

app.controller('CaricaCtrl', function ($scope, sendAndLoad) {
    console.log('carica');
    console.log($scope.codice_prodotto);
    // $scope.scanBarcode = function() {
    $scope.carica = function() {
	console.log('codice prodotto: '+ $scope.codice_prodotto);
...
```

---

<div class="post-metadata">

**Author:** ![Gajotres](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/gajotres/32/98564_2.png) [@Gajotres](https://forum.ionicframework.com/u/Gajotres)\
**Post date:** [July 28, 2015, 5:57pm UTC](https://forum.ionicframework.com/t/solved-get-input-value-in-to-controller/29391/2 "2015-07-28T17:57:37Z")

</div>

> [@coachdesign](#):
>
> codice\_prodotto

It’s:

```
$scope.codice_prodotto

```

Just like you used it.

Is your controller bound to **tpl/carica.html**?

---

<div class="post-metadata">

**Author:** ![coachdesign](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/coachdesign/32/13857_2.png) [@coachdesign](https://forum.ionicframework.com/u/coachdesign)\
**Post date:** [July 28, 2015, 6:00pm UTC](https://forum.ionicframework.com/t/solved-get-input-value-in-to-controller/29391/3 "2015-07-28T18:00:26Z")

</div>

yes my controller is:

```
.state('carica', {
	url: "/carica",
	templateUrl: "tpl/carica.html",
	controller: 'CaricaCtrl'
})

```

I seem to have used $scope.codice\_prodotto not?

---

<div class="post-metadata">

**Author:** ![Gajotres](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/gajotres/32/98564_2.png) [@Gajotres](https://forum.ionicframework.com/u/Gajotres)\
**Post date:** [July 28, 2015, 6:01pm UTC](https://forum.ionicframework.com/t/solved-get-input-value-in-to-controller/29391/4 "2015-07-28T18:01:39Z")

</div>

> [@coachdesign](#):
>
> sendAndLoad

I’m just guessing, I think your problem is this: **sendAndLoad**

Do you have this service and have you looked at your console logs?

If that object does not exist controller execution will fail.

---

<div class="post-metadata">

**Author:** ![coachdesign](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/coachdesign/32/13857_2.png) [@coachdesign](https://forum.ionicframework.com/u/coachdesign)\
**Post date:** [July 28, 2015, 6:04pm UTC](https://forum.ionicframework.com/t/solved-get-input-value-in-to-controller/29391/5 "2015-07-28T18:04:59Z")

</div>

Yes i’have this service:

```
app.service('sendAndLoad', function() {
	
	this.posM = '';
	this.posS = '';
	this.posP = '';
	
});
```

---

<div class="post-metadata">

**Author:** ![Gajotres](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/gajotres/32/98564_2.png) [@Gajotres](https://forum.ionicframework.com/u/Gajotres)\
**Post date:** [July 28, 2015, 6:07pm UTC](https://forum.ionicframework.com/t/solved-get-input-value-in-to-controller/29391/6 "2015-07-28T18:07:20Z")

</div>

What about console log?

Are you seeing this output:

console.log(‘carica’); ?

And what about this one:

console.log($scope.codice\_prodotto); ?

Have you received any error for this last line?

---

<div class="post-metadata">

**Author:** ![coachdesign](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/coachdesign/32/13857_2.png) [@coachdesign](https://forum.ionicframework.com/u/coachdesign)\
**Post date:** [July 28, 2015, 6:12pm UTC](https://forum.ionicframework.com/t/solved-get-input-value-in-to-controller/29391/7 "2015-07-28T18:12:32Z")

</div>

The output is:

```
2015-07-28 20:11:35.221 test[4500:2932243] carica
2015-07-28 20:11:35.222 test[4500:2932243] carica2

```

With this code:

```
console.log('carica');
console.log($scope.codice_prodotto);
console.log('carica2');
```

---

<div class="post-metadata">

**Author:** ![Praveena](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@Praveena](https://forum.ionicframework.com/u/Praveena)\
**Post date:** [July 28, 2015, 7:21pm UTC](https://forum.ionicframework.com/t/solved-get-input-value-in-to-controller/29391/8 "2015-07-28T19:21:38Z")

</div>

Pass the model object as parameter in the function try using below ng-click="carica(codice\_prodotto)"  
CARICA

and in the controller try using below pass the parameter i think it is not getting the scope of the input field  
$scope.carica = function(codice\_prodotto) {  
console.log('codice prodotto: '+ $scope.codice\_prodotto);

---

<div class="post-metadata">

**Author:** ![Gajotres](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/gajotres/32/98564_2.png) [@Gajotres](https://forum.ionicframework.com/u/Gajotres)\
**Post date:** [July 28, 2015, 7:24pm UTC](https://forum.ionicframework.com/t/solved-get-input-value-in-to-controller/29391/10 "2015-07-28T19:24:14Z")

</div>

> [@coachdesign](#):
>
> ng-model=“codice\_prodotto”

I got another idea, I so this once but completely forgot about it. Instead of this;

```
<input type="number" id="codice_prodotto" name="codice_prodotto" ng-model="codice_prodotto">

```

use this:

```
<input type="number" id="codice_prodotto" name="codice_prodotto" ng-model="codice_prodotto.value">

```

And in your controller:

```
console.log($scope.codice_prodotto.value);

```

###EDIT

You need to use dot notation with Ionic and input elements placed inside a ion-content container:

> [@Problem with ion-content and scope vars inside function](http://forum.ionicframework.com/t/problem-with-ion-content-and-scope-vars-inside-function/1811):
>
> Hi, scope variables are undefined inside controller function if input field with ng-model is inside ion-content. If I place the same input field outside ion-content, everything works as expected. I think I maybe missing something because if I recall properly several versions back that worked as it should. Please help. Thanks

---

<div class="post-metadata">

**Author:** ![coachdesign](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/coachdesign/32/13857_2.png) [@coachdesign](https://forum.ionicframework.com/u/coachdesign)\
**Post date:** [July 28, 2015, 9:18pm UTC](https://forum.ionicframework.com/t/solved-get-input-value-in-to-controller/29391/11 "2015-07-28T21:18:29Z")

</div>

I had already tried it, but it was printing even ‘console2’

---

<div class="post-metadata">

**Author:** ![coachdesign](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/coachdesign/32/13857_2.png) [@coachdesign](https://forum.ionicframework.com/u/coachdesign)\
**Post date:** [July 28, 2015, 9:20pm UTC](https://forum.ionicframework.com/t/solved-get-input-value-in-to-controller/29391/12 "2015-07-28T21:20:22Z")

</div>

I tried but I will return undefined ☹

---

<div class="post-metadata">

**Author:** ![coachdesign](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/coachdesign/32/13857_2.png) [@coachdesign](https://forum.ionicframework.com/u/coachdesign)\
**Post date:** [July 28, 2015, 9:41pm UTC](https://forum.ionicframework.com/t/solved-get-input-value-in-to-controller/29391/13 "2015-07-28T21:41:43Z")

</div>

Thank you both, so I solved.

```
<input type="tel" id="codice_prodotto" name="codice_prodotto" ng-model="settings.codice_prodotto">

<button nav-direction="back" class="button button-block button-large button-balanced" ng-click="carica(settings)">CARICA</button>

$scope.carica = function(settings) {
	console.log(settings);
	console.log('codice prodotto: '+ settings.codice_prodotto);
```

---

<div class="post-metadata">

**Author:** ![Gajotres](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/gajotres/32/98564_2.png) [@Gajotres](https://forum.ionicframework.com/u/Gajotres)\
**Post date:** [July 28, 2015, 10:49pm UTC](https://forum.ionicframework.com/t/solved-get-input-value-in-to-controller/29391/14 "2015-07-28T22:49:37Z")

</div>

So dot notation was a fix 😄

---

<div class="post-metadata">

**Author:** ![coachdesign](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/coachdesign/32/13857_2.png) [@coachdesign](https://forum.ionicframework.com/u/coachdesign)\
**Post date:** [July 29, 2015, 12:10am UTC](https://forum.ionicframework.com/t/solved-get-input-value-in-to-controller/29391/15 "2015-07-29T00:10:07Z")

</div>

Yes, with a different use 🙂

---

<div class="post-metadata">

**Author:** ![AnniDa](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@AnniDa](https://forum.ionicframework.com/u/AnniDa)\
**Post date:** [July 10, 2017, 4:48am UTC](https://forum.ionicframework.com/t/solved-get-input-value-in-to-controller/29391/16 "2017-07-10T04:48:41Z")

</div>

```auto
.controller('HomeCtrl', function($scope) {
  $scope.AddItem = function(data){
    console.info(data)
  };
  $scope.items=[
    {
      item : "Repair TV",
      status : false,
    },
    {
      item : "Do Nothing",
      status : true,
    },
  ];
})

```

help me with this

```auto

<div class="bar bar-footer item-input-inset">
      
        <label for="" class="item-input-wrapper">
          <input id="homeNewItem" type="text" placeholder="New Home ToDo" value="hello">
        </label>
        <button class="button button-small" ng-click="AddItem(document.getElementById('homeNewItem').value)">Add</button>
     
    </div>

```
