0

I have a simple AngularJS app with a single form that has 2 fields on it. I am trying to read the values entered in those 2 fields from my controller but for some reason I am always getting undefined. I have triple checked my code but can't find anything in it, so I hope someone can please help and tell me what I am doing wrong and how to fix it.

Note: I am using latest AngularJS release 1.2

app.js

'use strict';
var myApp = angular.module('myApp', ['ngRoute','ngSanitize']);
myApp.config(['$routeProvider', function($routeProvider) {
       $routeProvider.when('/index', 
                {     templateUrl: 'templates/common/index.html', 
                      controller: 'IndexController'
                }).
                when('/editcontact', 
                {     templateUrl: 'templates/contacts/editContact.html', 
                      controller: 'editContactController'
                }).
                otherwise({redirectTo: '/index'});
}]);

index.html

<!DOCTYPE html>
<html lang="en" ng-app="myApp">
  <head>
    <meta charset="utf-8">
    <title>myApp</title>
....
....
<script src="lib/angular/angular.js"></script>
  <script src="lib/angular/angular-route.js"></script>
  <script src="lib/angular/angular-sanitize.js"></script>
  <script src="js/app.js"></script>
  <script src="js/controllers/contacts/editContactController.js"></script>

  </body>
</html>

editContact.html

 <form name="editContactForm">
          <div>
            <fieldset>
              <input id="name" type="text" placeholder=Name..." ng-modal="contacts.name">
              <input id="phone" type="text" placeholder="Phone" ng-modal="contacts.phone">
            </fieldset>

            <button type="submit" ng-click="saveContact(contacts, editContactForm)">Save</button>
            <button type="button" ng-click="cancelEdit()">Cancel</button>
          </div>
         </form>

editContactController

myApp.controller('editContactController',
        function editContactController($scope){

         $scope.saveContact = function(contacts, editContactForm){
             if(editContactForm.$valid){
                 console.log(contacts.name);                
             }
         };
});  
1
  • 2
    ng-model not modalcarefull Commented Mar 6, 2014 at 23:58

1 Answer 1

1

You have a typo. ng-modal should be ng-model

<input id="name" type="text" placeholder=Name..." ng-modal="contacts.name">
<input id="phone" type="text" placeholder="Phone" ng-modal="contacts.phone">

should be

<input id="name" type="text" placeholder=Name..." ng-model="contacts.name">
<input id="phone" type="text" placeholder="Phone" ng-model="contacts.phone">
Sign up to request clarification or add additional context in comments.

1 Comment

OMG, I can't believe it is this...I spent literary hours on this and never noticed it!!! Thanks a lot for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.