Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 在ui路由器父状态下使用解析_Angularjs_Angular Ui Router - Fatal编程技术网

Angularjs 在ui路由器父状态下使用解析

Angularjs 在ui路由器父状态下使用解析,angularjs,angular-ui-router,Angularjs,Angular Ui Router,我试图使用Angular JS来使用一个简单患者数据库的web api,每个患者都有一个药物列表。 每个药物和患者都有自己的添加、编辑和列出操作。 当我试图编辑患者时,我添加了添加新药的选项(这也应该是编辑患者条目的一种方式)。 所以我使用了嵌套状态的嵌套状态概念,其中patient edit是父状态,patientedit是子状态,如下所示: .state("patientEdit", { abstract: true , url: "/patient/edit/:PatID"

我试图使用Angular JS来使用一个简单患者数据库的web api,每个患者都有一个药物列表。 每个药物和患者都有自己的添加、编辑和列出操作。 当我试图编辑患者时,我添加了添加新药的选项(这也应该是编辑患者条目的一种方式)。 所以我使用了嵌套状态的嵌套状态概念,其中patient edit是父状态,patientedit是子状态,如下所示:

.state("patientEdit", {
    abstract: true ,
    url: "/patient/edit/:PatID",
    templateUrl: "app/patients/patientEditView.html",
    controller: "PatientEditCtrl as vm",
    resolve: {
        patientResource: "patientResource",

        patient: function (patientResource, $stateParams) {

            console.log("the value of PatID is " + PatID);
            console.log("Patient Edit is called ???")
            return patientResource.get(
                { PatID: PatID }).$promise;

        }
    }
})

.state("patientEdit.Medications", {
    url: "/medications/:MedID/:PatID",
    templateUrl: "app/patients/patientEditMedicationsView.html",
    controller: "medicationEditCtrl as vm",
    resolve: {
        medicationResource: "medicationResource",

        medication: function (medicationResource, $stateParams) {
            var MedID = $stateParams.MedID;
            var PatID = $stateParams.PatID;
            console.log("the value of PatID is " + PatID);
            console.log("the value of MedID is " + MedID);
            console.log("Medication Edit is called ???");
            return medicationResource.getMedication(
                { MedID: MedID, PatID: PatID }).$promise;

        }
    }
})
return patientResource.get({ Id: PatID }).$promise;
单击“患者详细信息”视图中的按钮时,我会转换到“创建药物”(这是上面代码中的子状态,如下所示)

<a class="btn btn-primary"
    data-ui-sref="patientEdit.Medications({MedID: 0, PatID: vm.patient.ID})"
    style="width:160px">
     Creat New Medicine
</a>
medicationEditCtrl.Js

(function () {

    angular.module("patientManagement")
       .controller("medicationEditCtrl",
                    ["medication", "$state", medicationEditCtrl]);

    function medicationEditCtrl(medication, $state) {
        var vm = this;
        vm.medication = medication;
        console.log("we are in medication edit CTRL");
        if ((vm.medication.MedID)) {
            console.log("here is the controller of editing a medication ");
            vm.title = "Edit: " + vm.medication.Name;
        }
        else {
            console.log(vm.medication.MedID);
            console.log("having a patientId of " + vm.medication.PatID);
            vm.title = "New Medication";
        }
        vm.submit = function () {
            vm.medication.$save();
        }
        vm.cancel = function () {
            $state.go('patientList');
        }



    }

}());

以下是我使用的服务:

(function () {

"use strict";
angular.module("common.services")
       .factory("patientResource", ["$resource", patientResource]);

function patientResource($resource) {
    console.log("service is called");
    return $resource("http://localhost:49190/api/patients/:Id");

};

}());
当我使用(PatId)调用它时,所需的解决方案是将名为“patientEdit”的状态的解析中的服务调用更改为如下所示:

.state("patientEdit", {
    abstract: true ,
    url: "/patient/edit/:PatID",
    templateUrl: "app/patients/patientEditView.html",
    controller: "PatientEditCtrl as vm",
    resolve: {
        patientResource: "patientResource",

        patient: function (patientResource, $stateParams) {

            console.log("the value of PatID is " + PatID);
            console.log("Patient Edit is called ???")
            return patientResource.get(
                { PatID: PatID }).$promise;

        }
    }
})

.state("patientEdit.Medications", {
    url: "/medications/:MedID/:PatID",
    templateUrl: "app/patients/patientEditMedicationsView.html",
    controller: "medicationEditCtrl as vm",
    resolve: {
        medicationResource: "medicationResource",

        medication: function (medicationResource, $stateParams) {
            var MedID = $stateParams.MedID;
            var PatID = $stateParams.PatID;
            console.log("the value of PatID is " + PatID);
            console.log("the value of MedID is " + MedID);
            console.log("Medication Edit is called ???");
            return medicationResource.getMedication(
                { MedID: MedID, PatID: PatID }).$promise;

        }
    }
})
return patientResource.get({ Id: PatID }).$promise;

再次感谢您的时间和回复

以下是我使用的服务:

(function () {

"use strict";
angular.module("common.services")
       .factory("patientResource", ["$resource", patientResource]);

function patientResource($resource) {
    console.log("service is called");
    return $resource("http://localhost:49190/api/patients/:Id");

};

}());
当我使用(PatId)调用它时,所需的解决方案是将名为“patientEdit”的状态的解析中的服务调用更改为如下所示:

.state("patientEdit", {
    abstract: true ,
    url: "/patient/edit/:PatID",
    templateUrl: "app/patients/patientEditView.html",
    controller: "PatientEditCtrl as vm",
    resolve: {
        patientResource: "patientResource",

        patient: function (patientResource, $stateParams) {

            console.log("the value of PatID is " + PatID);
            console.log("Patient Edit is called ???")
            return patientResource.get(
                { PatID: PatID }).$promise;

        }
    }
})

.state("patientEdit.Medications", {
    url: "/medications/:MedID/:PatID",
    templateUrl: "app/patients/patientEditMedicationsView.html",
    controller: "medicationEditCtrl as vm",
    resolve: {
        medicationResource: "medicationResource",

        medication: function (medicationResource, $stateParams) {
            var MedID = $stateParams.MedID;
            var PatID = $stateParams.PatID;
            console.log("the value of PatID is " + PatID);
            console.log("the value of MedID is " + MedID);
            console.log("Medication Edit is called ???");
            return medicationResource.getMedication(
                { MedID: MedID, PatID: PatID }).$promise;

        }
    }
})
return patientResource.get({ Id: PatID }).$promise;
再次感谢您的时间和回复