Angular 不显示数据(Nodejs,Jade)



我的应用文件:

var app = angular.module('app', ['ngRecourse', 'ngRoute']);
app.config(function($routeProvider, $locationProvider){
$routeProvider.when('/', { templateUrl: 'partials/main.jade', controller: 'mainCtrl '})
$locationProvider.html5Mode(true);
});
angular.module('app').controller('mainCtrl,' function($scope){
$scope.myVar = "Hello Angular";
});

索引页与布局和所需的所有脚本连接:

extends ../includes/layout
block main-content
section.content
div(ng-view)

布局.翡翠 :

doctype
html
head
base(href='/')
link(href="/favicon.ico", rel="shortcut icon", type="image/x-icon")
link(rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous")
link(rel="stylesheet", href="/vendor/toastr/toastr.css")
link(rel="stylesheet", href="/css/site.css")
body(ng-app='app')
block main-content
include scripts

这是我的服务器:

app.get('/partials/:partialPath', function(req,res){
res.render('partials/' + req.params.partialPath);
});
app.get('*', function(req,res){
res.render('index.jade');
});

我尝试将应用程序脚本直接添加到索引中,但我得到的只是本地主机上的白屏......我正在使用Atom,并且我已经安装了我提到的所有软件包。谢谢你的时间!

在你的layout.jade中添加以下行以包含AngularJS:

script(src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js")

您还应该考虑从Jade迁移到Pug,它是一个较新的版本,具有更多功能和更少的错误。

最新更新