如何将数据传递给角度基础模态 $scope? [英] How to pass data to an angular-foundation modal $scope?

查看:30
本文介绍了如何将数据传递给角度基础模态 $scope?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 angular-foundation,特别是模态 http://madmimi.github.io/angular-foundation/#/modal ,我对如何在使用一个控制器时将数据传递给模态感到困惑,我想获取一个数组值并更新模态以显示特定的用户信息,例如:$scope.updateUserInfo = $scope.user[index] ,唯一的问题是如何将数据传递给 modal .

I am using angular-foundation and specifically the modal http://madmimi.github.io/angular-foundation/#/modal , i am confused in how to pass data to a modal while using one controller , i want to take an array value and update the modal to show a particular user info ,Ex: $scope.updateUserInfo = $scope.user[index] , the only issue is how to pass the data to the modal .

myApp.controller('users',function ($scope,$location,$http,$modal,msg) {
$http.get('api/v1/users')
.success(function (data,status) {
    $scope.user = data;
})
.error(function (data,status) {
    $location.path('/login');
});

$scope.showWrite = function () {
    $scope.write = true;
}

$scope.closeWrite = function () {
    $scope.write = false;
    $scope.newUser = '';
}

$scope.save = function () {
    $http.post('api/v1/users/store',$scope.newUser)
    .success(function (data,status) {

        $scope.user.unshift({
            id: data,
            first_name: $scope.newUser.first_name,
            last_name: $scope.newUser.last_name,
            email: $scope.newUser.email,
            role: $scope.newUser.role
        });

        $scope.write = false;
        $scope.newUser = '';
    })
    .error(function (data,status) {
        alert('failed');
    });
}

$scope.confirmDelete = function (index,id) {
    msg.confirmDelete().then(function(value) {
        $scope.text = msg.getText();
        $http.get('api/v1/users/destroy/'+id)
        .success(function  (data,status) {
            $scope.user.splice(index,1);
        })
        .error(function (data,status) {
            alert('Error : Operation failed');
        });
    });
}

$scope.showUserInfo = function () {

}

$scope.userUpdate = function () {

}


$scope.showUserUpdate = function (index) {
    $modal.open({
        templateUrl: 'partials/message/update.html',
        controller: 'users'
    });
}

});

推荐答案

要将数据传递给 $modal,您需要像这样更新 $modal 函数:

To Pass the data to $modal you need to update your $modal function something like this:

$scope.showUserUpdate = function (popUpData) {
    var modalInstance = $modal.open({
        templateUrl: 'partials/message/update.html',
        controller: ['$scope', '$rootScope', '$modalInstance', 
        function($scope, $rootScope, $modalInstance) {
            $scope = angular.extend($scope, popUpData);
        }],
        resolve: {}
    });
    return modalInstance;
};

所以 popupData 是你想传递给你的模态的数据.然后 popupdata 将与该控制器的现有范围合并.现在您可以访问 HTML 中的 popupData 键.请记住,我们在此函数中返回模态实例,因此您可以使用此实例手动关闭弹出窗口.

这篇关于如何将数据传递给角度基础模态 $scope?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆