将数据传递给模态

时间:2016-08-25 15:04:31

标签: angularjs

HTML

 <div ng-controller="aecaModalController as aecaModalC"
     ng-init='init({"data":"xxx"})'>
</div>

声明和控制器本身

function aecaModalController($scope,data){
     //How to get it here?
}    
app.controller('aecaModalController',aecaModalController);

模态开放定义

var modalInstance = $uibModal.open({
        animation: true,
        templateUrl: 'template.html',
        controller: 'aecaModalController as aecaModalC',
        openedClass: "custom-modal",
        size: 'lg',
        backdrop: 'static'
    });

如何将一些数据传递给模态并在打开时接收? 我不明白我怎么能这样做,这样:/

Resolve不起作用,我不得不按提供者转移对象:)

谢谢@Jhony Blaze

1 个答案:

答案 0 :(得分:0)

将解析属性添加到模态配置对象。 resolve属性值必须是具有返回所需值的函数属性的对象。

所以:

var modalInstance = $uibModal.open({
    animation: true,
    templateUrl: 'template.html',
    controller: 'aecaModalController as aecaModalC',
    openedClass: "custom-modal",
    size: 'lg',
    backdrop: 'static',
    resolve: {
        someVal: function () { return "someVal"; }
    }
});

然后,在模态实例控制器中按属性名称注入解析值:

function aecaModalController(someVal)  {
    this.injectedValue = someVal;
}

从那里,通过执行类似{{aecaModalC.injectedValue}}

的操作来访问视图中的injectValue变量