如何使用AngularJS监视自定义指令上的属性,以便接受要绑定的Angular值。
目前我的进展如下:
<tile title="Sleep Duration" data-value="{{sleepHistory.averageSleepTime}}"/>
app.directive('tile', [function() {
return {
restrict: 'E',
link: function(scope, element, attrs) {
var title = attrs.title;
attrs.$observe('dataValue', function(val) {
var data = val;
console.log(data);
var dom =
"<div>" +
"<p>" + title + "</p>" +
"<p>" + data + "</p>" +
"</div";
$(element).append($(dom.trim()));
});
}
};
}]);
但观察到的值返回为未定义