我正在尝试学习angularjs并且我不断收到此错误,这是我的代码:
app.js
var app = angular.module('DashboardApp',
[
'dashboardService'
]);
service.js
var dashboardServiceModule = angular.module('dashboardService', []);
dashboardServiceModule.factory('Dashboard', function ($http) {
return {
get_site: function () {
return $http({
method: 'GET',
url: 'www.google.com',
headers: {
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content'),
'Content-Type': 'application/x-www-form-urlencoded'
}
});
}
}
});
的index.html
<div class="row" ng-controller="Dashboard">
<input type="button" ng-model="template" value="www.google.com" ng-click="test()">
<remote-content></remote-content>
</div>
<script>
app.controller('dashboardCtrl', function (DashboardApp) {
console.log("a");
});
angular.module('DashboardApp').directive("remoteContent", ['Dashboard', function (Dashboard) {
return {
restrict: "E",
template: "<p>test</p>",
link: function (scope, elem, attrs) {
console.log("kl;sd");
}
}
}]);
</script>
非常感谢任何帮助,谢谢!
答案 0 :(得分:1)
您是否定义了ng-app
?此外,您的ng-controller
指令包含未定义的控制器'仪表板',而它应该是'dashboardCtrl'。改为:
<div ng-app="DashboardApp"> <!--If ng-app is not defined-->
<div class="row" ng-controller="dashboardCtrl">
<input type="button" ng-model="template" value="www.google.com" ng-click="test()">
<remote-content></remote-content>
</div>
</div>