Javascript 无法显示angularJS作用域组件
我正在使用AngularJS和Laravel制作一个web应用程序。该应用程序旨在允许用户在黑板上张贴注释。使用我的代码,当提交便笺时,它会保存到数据库中,但不会显示在页面上 angulartest.blade.php:Javascript 无法显示angularJS作用域组件,javascript,php,html,angularjs,laravel,Javascript,Php,Html,Angularjs,Laravel,我正在使用AngularJS和Laravel制作一个web应用程序。该应用程序旨在允许用户在黑板上张贴注释。使用我的代码,当提交便笺时,它会保存到数据库中,但不会显示在页面上 angulartest.blade.php: <!doctype html> <html lang="en" ng-app="app"> <title>Test angular</title> <link rel="stylesheet" href="css/boots
<!doctype html>
<html lang="en" ng-app="app">
<title>Test angular</title>
<link rel="stylesheet" href="css/bootstrap.css">
<body>
<div class="container" ng-controller="NoteController">
<h3>Add note</h3>
<form ng-submit="addNote()">
<input type="text" ng-model="newNote.content">
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
<ul>
<li ng-repeat="note in notes">
@{{ note.content }}
</li>
</ul>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</body>
</html>
我相信这是所有相关的代码。我不确定它为什么不显示note.content
谢谢因为数据更新不是从UI触发的,即在用户单击或类似活动时,范围可能不知道更改。在代码中,您正在更新来自服务的数据,因此我的第一个建议是使用$scope.$apply()将模型上的更改传播到UI
function parseNotes(data) {
$scope.notes = data;
if (!$scope.$$phase) {
$scope.$apply();
}
}
这可能会有帮助。如果没有,请发回我发现了我的错误,非常简单。在请求{{note.content}之前,我正在关闭div标记。它应该是这样的:
<div class="container" ng-controller="NoteController">
<h3>Add note</h3>
<form ng-submit="addNote()">
<input type="text" ng-model="newNote.content">
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<ul>
<li ng-repeat="note in notes">
@{{ note.content }}
</li>
</ul>
</div>
添加注释
提交
-
@{{note.content}
谢谢你的回复 你能在fiddle上提供你的代码吗?ajax请求在
Data.addNote
中是否返回完整的note对象?这里没有太多的疑难解答信息,它是由表单中的提交按钮触发的
<div class="container" ng-controller="NoteController">
<h3>Add note</h3>
<form ng-submit="addNote()">
<input type="text" ng-model="newNote.content">
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<ul>
<li ng-repeat="note in notes">
@{{ note.content }}
</li>
</ul>
</div>