Please see relevant jsFiddleAngularJS - html dưới chỉ thị của tôi không hiển thị
Trong tập tin này tôi có hai nhịp 'test1' và 'test2'. Khoảng 'test2' đang hiển thị nhưng khoảng cách bên dưới chỉ thị tùy chỉnh 'test1' của tôi không hiển thị hoặc được gọi vào trang. Tại sao?
<div ng-app="HelloApp">
<div ng-controller="MyCtrl">
<search-bar/> <!-- The Search Bar Directive -->
<span>test1</span>
</div>
<span>test2</span>
</div>
Mã kiễu góc
var app = angular.module('HelloApp', [])
app.directive('searchBar', function() {
return {
restrict: 'AE',
replace: true,
template: '<input type="text" ng-model="searchData" placeholder="Enter a search" id="searchbarid" />',
link: function(scope, elem, attrs) {
elem.bind('keyup', function() {
scope.$apply(function() {
scope.search(elem);
});
});
}
};
});
app.controller('MyCtrl', function($scope) {
var items = ["ask","always", "all", "alright", "one", "foo", "blackberry", "tweet","force9", "westerners", "sport"];
$scope.search = function(element) {
$("#searchbarid").autocomplete({
source: items
});
};
});
' ' dường như làm việc cho tôi –
timeiscoffee
@timeiscoffee đẹp catch..I've thêm phiên bản chi tiết của câu trả lời ... –
thể trùng lặp của [yếu tố kiễu góc chỉ thị không hiển thị khi sử dụng thẻ tự đóng] (http://stackoverflow.com/questions/18103183/angular-element-directives-not-displaying-when-using-self-closing-tags) – naXa