我是Angular的新手。我有一个指令,在linkFunction中我可以使用attributes [“attribute-value”]将范围设置为某个值。我期待element.html()提供指令的内部html。
.directive("sfGroupbar", function () {
var linkFunction = function (scope, element, attributes) {
scope.text = element.html();
scope.attr = attributes["text"];
};
return {
restrict: 'E',
templateUrl: "controls/groupbar.html",
link: linkFunction,
scope: {}
};
在我看来,我正在使用这样的指令......
<sf-groupbar warning="50" error="80" text="Web Server">Some Text</sf-groupbar>
在groupbar.html中,我正在使用代码......
<div ng-controller="groupbarController">
{{text}} <br />
{{attr}}
</div>
我原本希望看到“Some Text”和“Web Server”作为输出。我只获得Web Server作为输出,而不是“Some Text”,我得到以下作为输出......
<div ng-controller="groupbarController">
{{text}} <br />
{{attr}}
</div>
答案 0 :(得分:1)
您需要在范围定义中包含<?PHP
//now this is the link..
echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.($startrow+4).'">Next</a>';
?>
和其他属性,如此
validates :image, :presence => true
并且您可能还想将text
选项添加到scope { text : '=' }
以尝试获取指令中的文本。
我确定您有兴趣查看文档的这一部分
Directive to manipulate the DOM
答案 1 :(得分:1)
您必须将指令的transclude
属性设置为true
,并且必须在ng-transclude
或template
内包含templateurl
属性HTML元素,用于使指令的innerHTML呈现。
以下是基于您的代码
的工作插件http://embed.plnkr.co/sXoLPxeFA21fxzzeAcVs/preview
希望这有助于!!!!