0

I have run into a issue when trying to reference models with angularjs. I can get some of them to reference, but others are not working. I've included the code below:

function DeleteCustomers($scope, func) {
     $scope.delete = function() {
         func.deleteCustomer($scope.customer);
     }
 }


function UpdateCustomers($scope, func) {
    $scope.update = function() {
        func.updateCustomer({ name: $scope.name2, telephone: $scope.telephone2,
            email: $scope.email2, street: $scope.street2,
            city: $scope.city2, zipcode: $scope.zipcode2 });
        }
    }
}

And the html is

<div ng-controller="UpdateCustomers">
       <form class="test-angular-update">
           <input type="text" ng-model="name2"><br>
           <input type="text" ng-model="telephone2"><br>
           <input type="text" ng-model="email2"><br>
           <input type="text" ng-model="street2"><br>
           <input type="text" ng-model="city2"><br>
           <input type="text" ng-model="zipcode2"><br>
           <button class="button" ng-click="update()">Update</button><br>
       </form>
   </div>

   <br><br>
   <div ng-controller="DeleteCustomers">
       <form class="text-angular-delete">
           Customer Name <input type="text" ng-model="customer"><br>
           <button class="button" ng-click="delete()">Delete</button><br>
       </form>
   </div>

All the models from UpdateCustomers and DeleteCustomers are not being able to be referenced by the controllers. Any help would be appreciated.

Thanks!

2
  • 1
    It's not quite clear what your problem is, and your code is too incomplete to make a guess. Could you provide a jsFiddle that demonstrates the issue better? Commented Feb 23, 2013 at 7:17
  • The problem is that the ng-models under UpdateCustomers and DeleteCustomers are not being resolved. Thus, I cannot access them via $scope like I can with the other models. Commented Feb 23, 2013 at 13:34

1 Answer 1

2

Here's a more solid application structure, which might help ensure the func service is injected properly. Not sure if that's the issue you're having.

//app.js
var app = angular.module('app', []);

//services.js
app.factory('func', function(){/* service code*/});

//controllers.js
app.controller('DeleteCustomers', ['$scope', 'func', function($scope, func){
   $scope.delete = function() {
     func.deleteCustomer($scope.customer);
   };
}]);//edit had typo here missing ']'

EDIT: Working demo http://jsfiddle.net/grendian/Um3pR/

Sign up to request clarification or add additional context in comments.

2 Comments

this is what I put Module.controller('DeleteCustomers', [ '$scope', 'func', function($scope, func) { $scope.delete = function() { func.deleteCustomer($scope.customer); }; }]); no luck.
Edited original to fix type and include working demo. See if that helps.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.