我做了一个自定义指令:

js部分:

angular.module("myDirectives", []).directive("ngShowbox", function(){
  return {
    restrict: "E",
    scope: {
      title: "="
    },
    template: "<a href='#' ng-click='show($event)'>{{title}}</a>",
    controller: function($scope, $element){
      $scope.show = function(event){
        // do something...
      }
    }
  }
});

html部分:
<ng-showbox title="whatToPutHere??"></ng-showbox>

我想从title属性传递一些文本,
然后我的模板将显示文本。
我该怎么做?

非常感谢你 :)

最佳答案

在指令范围内使用@:

scope: {
      title: "@"
    },

Plunker为您:)

07-24 09:51
查看更多