【发布时间】:2018-06-01 08:13:46
【问题描述】:
电子 + AngularJS
我正在做一些基本的事情:我正在尝试添加将在每一页上显示的页眉和页脚。
所以我有这样的 app.js:
'use strict';
let app = angular.module('marks', ['ngRoute']);
app.controller('ctrl', ($scope) => {})
.config(($logProvider, $routeProvider) => {
$logProvider.debugEnabled(true);
$routeProvider
.when('/', {
templateUrl: 'html/home.html'
})
.when('/login', {
templateUrl: 'html/login.html'
})
.when('/teachers', {
// controller: 'js/teachers.controller.js',
templateUrl: 'html/teachers.html'
})
.when('/students', {
// controller: 'js/students.controller.js',
templateUrl: 'html/students.html'
})
.when('/404', {
templateUrl: 'html/404.html'
})
.otherwise({ redirectTo: '/404' });
});
footer.controller.js:
angular.module('marks').controller('MarksFooterController', ['$scope', ($scope) => {}]);
footer.directive.js:
angular.module('marks').directive('marksFooter', () => {
return {
restrict: 'EAC',
controller: 'MarksFooterController',
templateUrl: '../html/marks-footer.html'
};
});
marks-footer.html:
<div>
<h3>2017</h3>
</div>
和标题相同。
index.html
<!DOCTYPE html>
<html>
<head>
<script src="../../bower_components/angular/angular.js"></script>
<script src="../../bower_components/angular-resource/angular-resource.js"></script>
<script src="../../bower_components/angular-route/angular-route.js></script>
</head>
<body ng-app="marks">
<div class="tile is-ancestor is-12">
<div class="tile is-vertical is-parent is-9">
<ng-view></ng-view>
</div>
</div>
<script>
require('./app.js');
</script>
</body>
</html>
当我运行应用程序时,我没有收到任何错误,但指令是空的(但它们也有参数),那么问题是什么?
使用 DevTools 的屏幕截图:
我认为我以某种方式弄乱了控制器,但我不确定。
This answer 没有帮助。
感谢任何帮助
更新
现在我得到它试图以某种方式加载模板(也许标签位置的一些变化有所帮助),但应用程序找不到它。 DevTools -> Sources 未显示 html 文件夹 (screenshot)。我应该在哪里导入它?
已解决
解决方案是:
- 导入index.html的
<head>内的所有控制器和指令 - 将 templateUrl 更改为相对于 index.html 的路径
但我仍在寻找如何避免在 .html 中引入如此多的导入
【问题讨论】:
-
检查网络选项卡中模板 URL 上的
404。请记住,templateUrl路径是相对于 Web 根目录的,而不是 JavaScript 文件所在的当前文件夹。 -
@cgTag 路径很好,网络选项卡中没有错误。它甚至没有尝试加载
marks-footer.html -
你能发布你在哪里加载你的 JS 吗?我们看不到 app.js。我敢猜测
footer...js文件没有加载。 -
@Brian inside index.html 中的 :
<script>require('./app.js');</script> -
对,那么
app.js中的内容是什么?
标签: javascript angularjs electron