I have an AngularJS directive named, areaOne
. When I use template
the template is displayed but when I use templateUrl
in area1.js, template HTML is not rendered.
What am I missing here?
Server side: ASP.NET MVC 5
Client side: AngularJS 1
Source code is available here on github.
Project structure:
Root
Scripts
app.js
directives
area1.js
templates
area1.html
Views
Home
Index.cshtml
Index.cshtml
@{
ViewBag.Title = "Index";
}
@section Scripts{
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/app.js"></script>
<script src="~/Scripts/directives/area1.js"></script>
}
<h2>Index</h2>
<div ng-app="app">
<area-one></area-one>
</div>
app.js
(function() {
angular.module("app", []);
})();
area1.js
(function() {
angular.module("app")
.directive("areaOne", function() {
return {
restrict: 'E',
templateUrl: '~/templates/area1.html',
controller: function ($scope) {
$scope.button1Click = function () {
alert("button1 clicked");
}
}
}
});
})();
area1.html
<div>
<button id="button1" ng-click="button1Click()">Button 1</button>
</div>