0

angularjs でモデルを参照しようとすると、問題が発生しました。それらのいくつかを参照することができますが、他のものは機能していません。以下のコードを含めました。

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 });
        }
    }
}

そしてhtmlは

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

UpdateCustomers および DeleteCustomers からのすべてのモデルは、コントローラーによって参照できません。どんな助けでも大歓迎です。

ありがとう!

4

1 に答える 1

2

これは、func サービスが適切に挿入されるようにするのに役立つ、より堅固なアプリケーション構造です。それがあなたが抱えている問題かどうかはわかりません。

//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 ']'

編集:動作デモhttp://jsfiddle.net/grendian/Um3pR/

于 2013-02-23T18:38:02.333 に答える