如何将$ scope对象注入对话框模板?

时间:2022-03-18 11:03:19

I have this plunker with a dialog example that uses the resolve attribute of the option object, based on this example.
Basically what I want to do is to pass the title variable to be used in the dialog template:

我有这个plunker的对话框示例,它使用了选项对象的resolve属性,基于此示例。基本上我想要做的是传递要在对话框模板中使用的title变量:

var title         = "azerty";

Using the resolve attribute of the dialog options object:

使用对话框选项对象的resolve属性:

resolve:       {title: angular.copy(title)}

And then inject it to the dialog controller and assign it to a $scope variable:

然后将其注入对话框控制器并将其分配给$ scope变量:

controllers.DialogController = function($scope, dialog, title) {
    $scope.title = title;

But I get this Error:

但我得到这个错误:

Error: Unknown provider: azertyProvider <- azerty

错误:未知提供者:azertyProvider < - azerty

1 个解决方案

#1


10  

Starting with release 0.2.0 (https://github.com/angular-ui/bootstrap/blob/master/CHANGELOG.md#020-2013-03-03) we've updated the resolve syntax so it follows the one used by the $routeProvider. In practice it means that a value in the resolve object must be a function:

从版本0.2.0(https://github.com/angular-ui/bootstrap/blob/master/CHANGELOG.md#020-2013-03-03)开始,我们更新了解析语法,因此它遵循使用的语法由$ routeProvider。实际上,这意味着resolve对象中的值必须是一个函数:

resolve: {
  title: function() {
    return angular.copy(title);
  }
}

Here is the working plunk: http://plnkr.co/edit/qmNUsWK7RGeAjXcANuWv?p=preview

这是工作插件:http://plnkr.co/edit/qmNUsWK7RGeAjXcANuWv?p = preview

BTW, you don't need (and even should not) include Bootstrap's JavaScript. This project doesn't have dependencies on any external JavaScript (beside AngularJS itself) so you don't need jQuery either.

顺便说一下,你不需要(甚至不应该)包含Bootstrap的JavaScript。这个项目没有依赖任何外部JavaScript(除了AngularJS本身),所以你也不需要jQuery。

#1


10  

Starting with release 0.2.0 (https://github.com/angular-ui/bootstrap/blob/master/CHANGELOG.md#020-2013-03-03) we've updated the resolve syntax so it follows the one used by the $routeProvider. In practice it means that a value in the resolve object must be a function:

从版本0.2.0(https://github.com/angular-ui/bootstrap/blob/master/CHANGELOG.md#020-2013-03-03)开始,我们更新了解析语法,因此它遵循使用的语法由$ routeProvider。实际上,这意味着resolve对象中的值必须是一个函数:

resolve: {
  title: function() {
    return angular.copy(title);
  }
}

Here is the working plunk: http://plnkr.co/edit/qmNUsWK7RGeAjXcANuWv?p=preview

这是工作插件:http://plnkr.co/edit/qmNUsWK7RGeAjXcANuWv?p = preview

BTW, you don't need (and even should not) include Bootstrap's JavaScript. This project doesn't have dependencies on any external JavaScript (beside AngularJS itself) so you don't need jQuery either.

顺便说一下,你不需要(甚至不应该)包含Bootstrap的JavaScript。这个项目没有依赖任何外部JavaScript(除了AngularJS本身),所以你也不需要jQuery。