Ui bootstrap 将对象添加到控制器后不显示

Ui bootstrap doesn't show after adding object to controller

所以我的 ui bootstrap 模型 window 工作正常,但是当我将对象添加到控制器时,它停止显示并且在控制台中没有给我任何错误。

当我的控制器看起来像这样时:

"use strict";

app.controller('RegisterModalCtrl', ['$scope', '$location', '$uibModalInstance', '$http', 'ngAuthSettings', 'registerService',
function($scope, $location, $uibModalInstance, $http, ngAuthSettings, registerService) {

var $ctrl = this;

$ctrl.cancel = function() {
    $uibModalInstance.dismiss('cancel');
};
/*
$ctrl.registerInfo = {
    email: $ctrl.registerData.email,
    nick: $ctrl.registerData.nick,
    password: $ctrl.registerData.password,
    password_confirmation: $ctrl.registerData.confirm_password
};
*/

$ctrl.registerSubmit = function(registerInfo) {
    console.log('im in registerSubmit controller function');

    registerService.registerUser(registerInfo);
    $uibModalInstance.dismiss('cancel');
};

$ctrl.showCookiesRules = function() {
    $location.url("/cookiesrules");
    $uibModalInstance.dismiss('cancel');
};

$ctrl.showRules = function() {
    $location.url("/rules");
    $uibModalInstance.dismiss('cancel');
};
}]);

一切正常,但是当我删除 /* 就在 registerInfo 对象之前它停止显示。这个对象有什么问题?我希望它创建这个对象以在函数中传递它,然后将它传递给服务中的函数。

所以你应该做的是启动 $ctrl.registerInfo:

$ctrl.registerInfo = {};

控制器运行时数据不存在,因此您试图在没有不存在数据的情况下设置 $ctrl.registerInfo 的属性。填写表格后,将设置 properties/data。

另一种选择根本不进行初始化,只需将表单模型设置为registerData.confirm_password,然后在调用registerSubmit时调用它与 registerSubmit(registerData)。这会将数据发送到该方法,而无需在控制器中进行初始化:

<input type="text" placeholder="powtórz hasło"
        ng-model="registerData.confirm_password" />

<!-- abbreviated (other form fields here -->

<input type="submit" ng-click="registerSubmit(registerData)" />

如果以后需要数据,在registerSubmit中添加一行:

$ctrl.registerInfo = registerInfo;

但是,我不确定您是否愿意保留密码。

AngularJS 表单文档:https://docs.angularjs.org/guide/forms