我已经创建了一个指令但是.directive代码永远不会被执行。我确定问题是显而易见的,但我无法看到它:
<!DOCTYPE html>
<html lang="en-US">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body>
<div ng-app="app">
<responsive-parent>xxx</responsive-parent>
</div>
<script>
angular.module("mrpmorris.responsive-parent", [])
.directive("responsive-parent", [
"$window", "$timeout",
function ($window, $timeout) {
console.log("**** THIS IS NEVER REACHED ****");
return new mrpmorris.responsiveParent.Directive($window, $timeout);
}
]);
var mrpmorris;
(function (mrpmorris) {
var responsiveParent;
(function (responsiveParent) {
var Directive = (function () {
function Directive($window, $timeout) {
var _this = this;
this.$window = $window;
this.$timeout = $timeout;
this.restrict = "E";
this.template = "<h1>It works</h1>";
this.replace = true;
}
return Directive;
}());
responsiveParent.Directive = Directive;
})(responsiveParent = mrpmorris.responsiveParent || (mrpmorris.responsiveParent = {}));
})(mrpmorris || (mrpmorris = {}));
angular.module("app", ["mrpmorris.responsive-parent"]);
</script>
</body>
</html>
答案 0 :(得分:3)
该指令应命名为responsiveParent
,而不是responsive-parent
。
但在视图中仍然会使用responsive-parent
。
the documentation中解释了这一点。