javascript - 模态内的 Angular 路线

标签 javascript angularjs angular-ui-bootstrap angular-ui-modal

我有 2 条路线:

app.config(['$routeProvider', '$locationProvider', function(
  $routeProvider, $locationProvider) {
    $routeProvider.
    when("/list/:class", {
        controller: "listController",
        templateUrl: "DatabaseObject",
        reloadOnSearch: true
    }).
    when("/edit/:class/:id?", {
        templateUrl: "editortemplate"
    }).
    otherwise("/custombrowsingstartpage");
}]);

他们都工作得很好!

我想要的是能够在“/list/:class”路由的模态窗口中呈现其中一条路由的“editortemplate”。

在我的“listController”中,我有模态打开功能:

    $scope.showEditorPanel = function (size, a, b) {
      //console.log($scope);
      var modalInstance = $modal.open({
      animation: true,
      //templateUrl: '#/edit/'+b+'/'+a,
      templateUrl: 'editortemplate',
      controller: 'editorController',
      size: size,
      backdrop: true,
      scope: $scope
    });

模板呈现得很好,但我不知道如何将模板所需的类和 id 变量传递给它(如其路由所示)。

我尝试用变量(class== var b,id== var a)而不是模板 url 定义路由,但没有成功:

//templateUrl: '#/edit/'+b+'/'+a,

最佳答案

如果您添加一个“解决”对象,您可以发送您想要的内容,我相信这是使用 $modal 执行此操作的“Angular ”方式:

$scope.showEditorPanel = function (size, a, b) {
  var modalInstance = $modal.open({
  animation: true,
  templateUrl: 'editortemplate',
  controller: 'editorController',
  size: size,
  backdrop: true,
  resolve: {
           scope: function () {
                            $scope.properties.class = a;
                            $scope.properties.id = b;
                            return $scope.properties;
                        }
           }
});

关于javascript - 模态内的 Angular 路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32783936/

相关文章:

javascript - Kintone 时间字段的自定义时间增量

javascript - Hapi 不从 Boom 错误返回数据属性

javascript - bootstrap typeahead 指令不适用于输入字段

angularjs - 在 ui-grid AngularJs 中重新显示隐藏列

javascript - UIB 选项卡集不起作用

javascript - AngularJS:UI Bootstrap Popover 放置 'bottom-right'

javascript - 为什么 React Router v6 不渲染我的组件?

javascript - 异步加载脚本并有回退

javascript - 从 JSON 生成动态条件表单字段 - AngularJS1.x

javascript - 在 Angular 状态更改后激活特定选项卡