最终目标传递属性值指令模板
我们希望有我们可以添加到我们会联想到一个上下文帮助对话框上的任何元素的属性,这样,当我们将鼠标游标移到元素,弹出窗口会显示帮助信息。下面是我们想要做的一个例子:
<label help-info="This is what will be displayed in the help dialog">Help Example</label>
我遇到了一些麻烦正确地传递字符串参数模板虽然。
这是我已经试过:
的Index.html
<html ng-app="myApp">
<head>
<script data-require="[email protected]*" data-semver="2.0.0-alpha.20" src="https://code.angularjs.org/2.0.0-alpha.20/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="HelpInfoDirective.js"></script>
</head>
<body ng-controller="myCtrl">
<div help-info="test"></div>
</body>
</html>
HelpInfoTemplate.html
<div>
{{'this is a' + _attrs.help-info}}
</div>
HelpInfoDirective.js
(function(){
var app = angular.module('myApp', []);
app.directive('helpInfo', function(){
return{
restrict: 'A',
scope: true,
templateUrl: function(_elements, _attrs){
'HelpInfoTemplate.html'
}
// link: function(_scope, _elements, _attrs){
// _scope.helpAttr = _attrs.help-info;
// }
}
});
})();
首先,我尝试通过使用链接参数传递参数,它没有工作,所以我尝试将模板放入一个没有运气的函数。
将属性值传递给模板的正确方法是什么?另外,一旦我们有了价值,我们如何修改返回的模板,以便我们可以使用ng-show
来显示弹出窗口(我们将最终将它放置到模式中)。我接受建议。
链接到Plunk
你想要一个弹出窗口或工具提示吗? – jake
我们正在创建一个自定义弹出窗口来包装字符串。我们正在计划基于类似于