I am new to AngularJs and Ionic, I am trying to follow this example to create simple app but it is just showing blank screen and there is no error on console log.
我是AngularJs和Ionic的新手,我试着用这个例子来创建一个简单的应用程序,但它只是显示空白屏幕,在控制台日志上没有错误。
index.html
index . html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controller.js"></script>
</head>
<body ng-app="bloggerDemo">
<ion-pane>
<ion-nav-bar class="bar-positive"></ion-nav-bar>
<ion-nav-view></ion-nav-view>
</ion-pane>
</body>
</html>
latestPosts.html
latestPosts.html
<ion-view title="Latest Posts">
<ion-content>
<ion-list>
<ion-item ng-repeat="latestPost in latestPosts" class="item item-icon-right" sref="latestPosts.singlePost({post: $index})">
<span>{{latestPost.title}}</span>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
singlePost.html
singlePost.html
<ion-view title="Single Post">
<ion-content padding='true'>
<h1>{{post.title}}</h1>
<section>{{post.description}}</section>
</ion-content>
</ion-view>
app.js
app.js
var app = angular.module('bloggerDemo', ['ionic'])
app.config(function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/latestPosts')
$stateProvider.state('latestPosts', {
abstract: true,
url: '/latestPosts',
template: '<ion-nav-view></ion-nav-view>'
})
$stateProvider.state('latestPosts.index', {
url: '/latestPosts',
templateUrl: 'templates/latestPosts.html',
controller: 'PostsCtrl'
})
$stateProvider.state('latestPosts.singlePost', {
url: '/:singlePost',
templateUrl: 'templates/singlePost.html',
controller: 'SinglePostCtrl',
resolve: {
singlePost: function ($stateParams, PostService) {
return PostService.getPost($stateParams.post)
}
}
})
})
app.controller('PostsCtrl', function ($scope, PostService) {
$scope.latestPosts = PostService.latestPosts
})
app.controller('PostCtrl', function ($scope, singlePost) {
$scope.singlePost = singlePost
})
app.factory('PostService', function () {
var posts = [
{
title: 'lkad alkjdflak dfkljad f alkdsjf al',
description: 'adflkajd fjad faldfj aldkjf lkdfj lakdj flaksd flkds flksdj flkadlkfkhaghoiahd fkasdjkasdjfkl ajf sdjfalksdj falj falkf '
},
{
title: 'lkad alkjdflak dfkljad f alkdsjf al',
description: 'adflkajd fjad faldfj aldkjf lkdfj lakdj flaksd flkds flksdj flkadlkfkhaghoiahd fkasdjkasdjfkl ajf sdjfalksdj falj falkf '
}
];
return {
latestPosts: posts,
getPost(function (post) {
return latestPosts[post]
})
}
})
2 个解决方案
#1
0
try changing this:
试着改变:
<ion-list>
<ion-item ng-repeat="latestPost in latestPosts" class="item item-icon-right" sref="latestPosts.singlePost({post: $index})">
<span>{{latestPost.title}}</span>
</ion-item>
</ion-list>
for this:
:
<ion-list>
<ion-item ng-repeat="latestPost in latestPosts" class="item item-icon-right">
<a ui-sref="latestPosts.singlePost({post: latestPost.post_id })">
{{latestPost.title}}
</a>
</ion-item>
</ion-list>
Hope this Help you...
希望这有助于你…
#2
0
after I read your code, I think I found the problem exist in your app.js
在我阅读了您的代码之后,我认为我发现问题存在于您的app.js中
change this:
改变:
$stateProvider.state('latestPosts', {
abstract: true,
url: '/latestPosts',
template: '<ion-nav-view></ion-nav-view>'
})
to this:
:
$stateProvider.state('latestPosts', {
abstract: true,
url: '/latestPosts',
template: "/templates.index.html"
})
It is essential to note that the abstract state always point to where the <ion-nav-view>
exist.
必须注意,抽象状态总是指向
Tell me if it works, Happy Coding.
告诉我它是否有效,快乐编码。
#1
0
try changing this:
试着改变:
<ion-list>
<ion-item ng-repeat="latestPost in latestPosts" class="item item-icon-right" sref="latestPosts.singlePost({post: $index})">
<span>{{latestPost.title}}</span>
</ion-item>
</ion-list>
for this:
:
<ion-list>
<ion-item ng-repeat="latestPost in latestPosts" class="item item-icon-right">
<a ui-sref="latestPosts.singlePost({post: latestPost.post_id })">
{{latestPost.title}}
</a>
</ion-item>
</ion-list>
Hope this Help you...
希望这有助于你…
#2
0
after I read your code, I think I found the problem exist in your app.js
在我阅读了您的代码之后,我认为我发现问题存在于您的app.js中
change this:
改变:
$stateProvider.state('latestPosts', {
abstract: true,
url: '/latestPosts',
template: '<ion-nav-view></ion-nav-view>'
})
to this:
:
$stateProvider.state('latestPosts', {
abstract: true,
url: '/latestPosts',
template: "/templates.index.html"
})
It is essential to note that the abstract state always point to where the <ion-nav-view>
exist.
必须注意,抽象状态总是指向
Tell me if it works, Happy Coding.
告诉我它是否有效,快乐编码。