角度因素呼叫不起作用

我试图在工厂调用update / put方法,然后通过API调用将表单上的更改保存到数据库中。 但是我在下面看到一个控制台错误。 更新函数从按钮点击调用正常,但它不会从那里调用工厂和API。 我错过了什么? 谢谢!

我用下面的建议更新了我的代码,但是现在有这个错误:

我的控制台错误:“错误:[$ injector:unpr] http://errors.angularjs.org/1.2.10/$injector/unpr?p0=%24resourceProvider%20%3C-%20%24resource%20%3C-%20%24resource%20%3C- %20memberUpdate


var securityApp = angular.module('securityApp',['ngRoute'])。 config(function($ routeProvider){

$routeProvider

    .when('/', {
        templateUrl: 'PartialPages/members.html',
        controller: 'membersController'
    })

    .when('/memberDetail/:memberID', {
        templateUrl: 'PartialPages/memberDetail.html',
        controller: 'memberDetailController'
    })

    .when('/memberEdit', {
        templateUrl: 'PartialPages/memberEdit.html',
        controller: 'memberEditController'
    });

});


securityApp.factory('memberUpdate', function ($resource) {       
    return $resource('/api/Members/:id', { id: '@id' }, { update: { method: 'PUT' } });
});


securityApp.controller('memberDetailController', function ($scope, $http, $routeParams, memberUpdate) {

    var id = $routeParams.memberID;

    $http.get('/api/Members/' + $routeParams.memberID).success(function (data) {
        $scope.member = data;
    })
    .error(function () {
        $scope.error = "An Error has occured while loading posts!";
    })

    $scope.update = function () {
        memberUpdate.update({ id: id }, $scope.member);
    };

});

$resource is in a different module  so you need to include it.
var securityApp = angular.module('securityApp', ['ngRoute', 'ngResource']).

她如何安装它https://docs.angularjs.org/api/ngResource


您需要将memberUpdate注入到控制器依赖项中。

securityApp.controller('memberDetailController', function ($scope, $http, $routeParams, memberUpdate) {

    var id = $routeParams.memberID;

    $http.get('/api/Members/' + $routeParams.memberID).success(function (data) {
        $scope.member = data;
    })
    .error(function () {
        $scope.error = "An Error has occured while loading posts!";
    })

    $scope.update = function () { // you don't need to pass $scope and memberUpdate since they are already available into the scope
        memberUpdate.update({ id: id }, $scope.member);
    };

});
链接地址: http://www.djcxy.com/p/13599.html

上一篇: Angular Factor Call not working

下一篇: Default $resource POST data