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!
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/