【发布时间】:2013-05-18 01:39:56
【问题描述】:
我知道我可以apply 到模板/模板URL,但目前内容将从我的应用程序的另一个位置加载。
JSbin:http://jsbin.com/imuseb/1/
HTML
<html ng-app="app">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
</head>
<body>
<div alert>here</div>
</body>
</html>
JS代码:
var app = angular.module('app', []);
app.directive('alert', function (){
return {
link: function (scope, element, attrs) {
element.on("click", function (){
alert("here");
});
}
};
});
$(function (){
$("body").append("<div alert>here too</div>");
});
【问题讨论】:
-
到目前为止你尝试了什么?能否提供一些示例代码?
标签: javascript html angularjs angularjs-directive