最終目標傳遞屬性值指令模板
我們希望有我們可以添加到我們會聯想到一個上下文幫助對話框上的任何元素的屬性,這樣,當我們將鼠標遊標移到元素,彈出窗口會顯示幫助信息。下面是我們想要做的一個例子:
<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
我們正在創建一個自定義彈出窗口來包裝字符串。我們正在計劃基於類似於