使用angular JS创建SPA时无法从视图页面加载内容 [英] Unable to load content from views pages while creating SPA using angular JS
问题描述
我遇到的问题是我的观点没有显示主页面上的值。我正在尝试使用Angular JS创建SPA(单页应用程序)。
我保留了三个html页面(main,about和blog).html in一个名为pages的单独文件夹。
每次我运行这个应用程序的内容写在三个html页面(main,about和blog).html对我来说是不可见的..
请重新查看我的代码并告诉我我的错误是什么
我尝试过:
我的主页(index.html)
<!DOCTYPE html>
< title>
I'm facing a problem in which my views are n't showing the values on the main page. I am trying to create a SPA(Single Page Application) using Angular JS.
I've kept the three html pages (main,about and blog).html in a separate folder named pages.
Everytime I run this application the contents written in three html pages (main,about and blog).html invisible to me..
Kindly re-view my code and tell me what's my mistake
What I have tried:
My main page(index.html)
<!DOCTYPE html>
<title>
< h1> Home< / h1>
< h3> {{message }< / h3>
< h1> Blog< / h1>
< h3> {{message}}< / h3>
< h1>关于< / h1>
< h3> {{message}}< / h3>
主页
博客
关于
<h1>Home</h1>
<h3>{{message}}</h3>
<h1>Blog</h1>
<h3>{{message}}</h3>
<h1>About</h1>
<h3>{{message}}</h3>
Home
Blog
About
我的脚本页面
var app = angular.module('myApp',['ngRoute']);
app.config (函数($ routeProvider){
$ routeProvider
.when('/',{
templateUrl :'pages / home.html',
控制器:'HomeController'
})
.when ('/ blog',{
templateUrl:'pages / blog.html',
controller:'BlogController'
})
.when('/ about',{
templateUrl:'pages / about.html',
controller:'AboutController'
})
。其他({redirectTo:'/'});
});
app.controller('HomeController',函数($ scope){
$ scope.message ='来自HomeController的Hello';
});
app.controller('BlogController',函数($ scope){
$ scope.message = '你好,来自BlogController';
});
app.controller('AboutController',函数($ scope){
$ scope.message ='你好,来自AboutController';
});
我的home.html页面
首页
{{message}}
我的博客.html页面
博客
{{m essage}}
我的about.html页面
关于
{{message}}
推荐答案
routeProvider){
routeProvider) {
routeProvider
.when('/',{
templateUrl: 'pages / home.html',
控制器:'HomeController'
})
.when( '/ blog',{
templateUrl:'pages / blog.html',
controller:'BlogController'
})
。当('/ about',{
templateUrl:'pages / about.html',
控制器: 'AboutController'
})
。其他({redirectTo:'/'});
} ); $
app.controller('HomeController',函数(
routeProvider
.when('/', {
templateUrl: 'pages/home.html',
controller: 'HomeController'
})
.when('/blog', {
templateUrl: 'pages/blog.html',
controller: 'BlogController'
})
.when('/about', {
templateUrl: 'pages/about.html',
controller: 'AboutController'
})
.otherwise({ redirectTo: '/' });
});
app.controller('HomeController', function (
scope){
scope) {
这篇关于使用angular JS创建SPA时无法从视图页面加载内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!