ui-route in AngularJS showing empty page
我正在尝试按照本教程学习 AngularJS:https://thinkster.io/mean-stack-tutorial。
我在它说”创建新评论”之前就开始了。我遇到的问题是,当我单击”评论”时,会出现一个只有一条水平线的空白页面。
我的理解是帖子的标题应该在两条虚假评论的顶部。这是我的代码:
index.html:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
<!DOCTYPE html>
<html> <head> Flapper News <!– BOOTSTRAP –> <!– ANGULARJS –> <style> .glyphicon–thumbs–up { cursor:pointer } </style> <body ng–app=“flapperNews” style=“padding: 50px”> <!– Inline home template –> <!– Show all the posts –> <br /> <!– Form to make new posts –> <button type=“submit” class=“btn btn-primary” ng–click=“submit”>Post</button> <!– Inline Posts section –> <!– Display title as header –> <!– Display the comment –> |
app.js
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
var app = angular.module(‘flapperNews’, [‘ui.router’]);
app.factory(‘posts’, [function() { return o; app.config([ function($stateProvider, $urlRouterProvider) { $stateProvider $urlRouterProvider.otherwise(‘home’); app.controller(‘MainCtrl’, [‘$scope’, ‘posts’, function($scope, posts) { $scope.addPost = function() { $scope.posts.push({ $scope.title = ”; $scope.incrementUpvotes = function(post) { }]); app.controller(‘PostsCtrl’, [ |
我不确定我做错了什么让它什么都不显示。任何帮助将不胜感激,谢谢!
控制台错误:
The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol.
Use of getPreventDefault() is deprecated. Use defaultPrevented instead.
- 似乎是路径问题或配置问题。能不能放个简单的plnkr
- 您是否在控制台中收到错误
- 以前从来没有用过plnkr,打算把它放在那里。我在 OP 中发布了错误。
- @Gary对不起,似乎无法在 plnker 中显示任何内容。不知道我做错了什么。
- 是浏览器的问题吗?当我点击”评论”时,我仍然得到一个空白页。
由于多个问题,您的代码将无法运行:
1. 您没有将 addPosts() 中的任何 id 属性添加到您的 posts 中,而是在访问 posts.posts[‘$stateParams.id’] 时期望它。
我创建了一个 jsbin 来添加 id 属性并修复其他问题,它现在可以工作了。
来源:https://www.codenong.com/36660321/