从模态传递角度值

时间:2014-03-15 21:39:50

标签: angularjs angularjs-scope

我在Angular中有一个模态窗口,按下按钮时会打开。

当模态打开时,我有一个按钮列表,里面有图像。这方面的例子如下。

我正在尝试检测ng-click="chosen(pink)"何时发生,以便它使用值$scope写入主要应用pink,但是当我运行以下内容时,它会写入console.log { {1}}

undefined

HTML

    $scope.choosepin = function () {
        var modalInstance = $modal.open({
            templateUrl: 'template/modal-choose-pin.html',
            controller: ModalInstanceCtrl3,
            resolve: {},
            scope: $scope.$new()
        });
        modalInstance.result.then(function (selectedItem) {
            $scope.user.pin = selectedItem;
            console.log($scope);
        });

    };

ModalInstanceCtrl3 = function ($scope, $modalInstance) {
        $scope.input = [];

        $scope.ok = function () {
            $modalInstance.close($scope.pin);
            $scope.gps = "";
            $scope.title = "";
        };

        $scope.cancel = function () {
            $modalInstance.dismiss('cancel');
        };

        $scope.chosen = function(index) {
            console.log(index);
        }
    };

1 个答案:

答案 0 :(得分:0)

ng-click指令期待expression并且因为它寻找名为 pink 的$ scope变量,当然它是未定义的,因为你没有这样的变量在你的控制器中。

如果你想发送字符串作为参数,你应该这样做,

ng-click="chosen('pink')"