【问题标题】:AngularJS/HTML - trying to escape close tag in custom directiveAngularJS/HTML - 试图在自定义指令中转义关闭标签
【发布时间】:2015-09-10 10:10:31
【问题描述】:

我正在尝试查看是否有一种使用自定义指令来选择地址的好方法来实现 ng-bootbox。

这是一个基本示例

  <button class="btn btn-lg btn-primary" 
      ng-bootbox-title="A cool title!"
      ng-bootbox-custom-dialog="<h1>zzzzzzzzzzzzzzz!</h1>"
      ng-bootbox-buttons="customDialogButtons"
      ng-bootbox-options="dialogOptions">
          Custom dialog with template
  </button>

这里我有引号必须匹配的消息。我也试过这个:

ng-bootbox-custom-dialog="<h1>zzzzzzzzzzzzzzz!<'/'h1>"

这样做破坏了我的 H1 并呈现了这个

'/'h1>"

我最终想这样做:

ng-bootbox-custom-dialog="<qas-modal-find-postcode address='record.address' town='record.town' county='record.County' post-code='record.postcode'></qas-modal-find-postcode>"

按钮在模态中加载指令,我有一些两种方式的绑定可以使用。

我想知道一个好的方法。我没有使用引导模式,因为我遇到了多个 Id 相同的冲突。

Plunker:

Angular with ng-bootbox

【问题讨论】:

  • 一个这样的样本 plunker 会很棒
  • @ManuelMiranda 你说得很好。我会设置一个。

标签: html angularjs bootstrap-modal bootbox html-escape-characters


【解决方案1】:

根据您的小提琴,我更改了一些拼写错误并编辑了您的 $ngBootbox 指令,如下所示:

plunker:http://plnkr.co/edit/3iMVoaNyn7zJA2ZCj5xC?p=preview

主 ajs 文件:

angular.module('myapp', ['ngBootbox'])
    .controller('myappController', function($scope) {

        $scope.record = {};
        $scope.record.Country = "UK";
        $scope.record.postcode = "SW12 4RT";
        $scope.record.County = "Some county";
        $scope.record.town = "some town";

    })
    .directive('qasModalFindPostcode', function () {
   return {
       templateUrl: 'tmplModalQasPostcode.html',
       restrict: 'E',
       scope: {
           postCode: '=',
           address: '=',
           town: '=',
           county: '='
       },
       link: function (scope, element, attrs) {

               scope.doSearch = function () {
                 alert(scope.modelTest)
                 console.log(scope);
                  scope.modelTest = "some text"
               }
      }
   }

});

模态模板tmplModalQasPostcode.html:

<div>
    <button ng-click="doSearch('test')">dsdffsdfsd</button>
    <input type="text" ng-model="modelTest">
    {{modelTest}}
</div>

ngBootbox custonDialog函数(在else末尾添加2行编译模板:

customDialog: function (options) {
        if (options.templateUrl) {
          getTemplate(options.templateUrl)
            .then(function (template) {
              options.scope = options.scope || $rootScope;
              options.message = $compile(template)(options.scope);
              $window.bootbox.dialog(options);
            })
            .catch(function () {
              $window.bootbox.dialog(options);
            });
        }
        else {
          options.scope = options.scope || $rootScope;
          options.message = $compile(options.message)(options.scope);
          $window.bootbox.dialog(options);
        }
      },

希望对你有帮助

【讨论】:

  • 嘿,你的代码可以工作,但我现在唯一的问题是没有双向绑定。我不知道这是否可能,但这就是我想要做的。按钮事件处理程序只是一个简单的示例。
  • 您到底需要什么?
  • 我希望有两种方式绑定,因为它是一个指令。例如,指令的父级设置了一些数据,我想通过指令传递这些数据并将其放在模式中。这可能吗?
  • 再看一次。那是你需要的吗?
  • 是的,这很完美。 Muchos gracias por la ayuda!你想更新你的帖子吗?我会接受的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-02
  • 1970-01-01
  • 2013-01-05
  • 2014-06-24
  • 2013-02-19
  • 2017-08-12
相关资源
最近更新 更多