【问题标题】:Assign custom attribute of angular directive in a Html Helper element Razor在 Html Helper 元素 Razor 中分​​配 angular 指令的自定义属性
【发布时间】:2016-06-29 17:29:58
【问题描述】:

这里我正在编写如下的角度自定义指令属性

var app = angular.module('myApp', ['ui.bootstrap']);

    app.directive('myDirective', function () {
        return {
            restrict: 'A',
            link: function (scope, el) {
                el.bind('blur', function () {
                    alert('hi');
                });
            }
        }
    });

我有一个使用剃须刀的视图。所以我的问题是如何将此指令属性注入我的 htmlHelper 元素。我的 Html Helper 元素如下

  @Html.TextBoxFor(m => m.Name, new { @class = "form-control testcss", required = "true", ng_model = "Name", uib_popover = "I have a title!", popover_toggle = "focus" })

当我简单地将属性注入“my_directive”时,它会显示“无效的匿名类型成员声明器”。

感谢您的帮助。谢谢!!

【问题讨论】:

    标签: angularjs asp.net-mvc-4 razor


    【解决方案1】:

    我遇到了类似的问题。您可以通过将@my_directive="" 添加到匿名类的列表中来解决此问题。似乎用空值声明时,它只会添加没有值的属性(因此,它将呈现为 input type="text" my-directive id="myID"...) .

    希望对您有所帮助! 史蒂夫

    【讨论】:

      猜你喜欢
      • 2016-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-17
      • 1970-01-01
      • 1970-01-01
      • 2017-04-30
      相关资源
      最近更新 更多