本文介绍了AngularJS NG-视图不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我遵循这个指南:http://viralpatel.net/blogs/angularjs-routing-and-views-tutorial-with-example/

但是,当我试图改变视图没有任何反应,任何一个知道我做错了什么?

这是code我。
Home.php:

 <!DOCTYPE HTML>
< HTML NG-应用=宽松>
< HEAD>
    < META NAME =作者内容=公园Desmedt/>
    < META NAME =说明内容=CMS比利时长曲棍球/>
    < META NAME =关键词内容=长曲棍球,BLF,比利时/>
    < META NAME =Googlebot的内容=无存档/>
    <链接HREF =LIB /引导/ CSS / bootstrap.css的rel =stylesheet属性>
    &所述; SCRIPT SRC =htt​​ps://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js>&下; /脚本>
    &所述; SCRIPT SRC =lax.js>&下; /脚本>
    <链接HREF =CSS / style.css文件的rel =stylesheet属性>
    <标题> CMS比利时曲棍球< /标题>
< /头>
<身体GT;
    <头类=导航栏导航栏,导航栏逆固定顶BS-文档-NAV角色=大旗>
        < D​​IV CLASS =容器>
            < D​​IV CLASS =导航栏头>
                <按钮类=导航栏拨动式=按钮数据切换=崩溃数据目标=BS-导航栏崩溃>
                    <跨度类=SR-只有>拨动导航< / SPAN>
                    <跨度类=图标栏>< / SPAN>
                    <跨度类=图标栏>< / SPAN>
                    <跨度类=图标栏>< / SPAN>
                < /按钮>
            < / DIV>
            <导航类=导航栏崩崩BS-导航栏崩溃角色=导航>
                < UL类=NAV导航栏,导航栏导航左>
                    <立GT;
                        < A HREF =#/家>
                            <跨度类=glyphicon glyphicon家>< / SPAN> BLF
                        &所述; / A>
                    < /李>
                    <立GT;
                        < A HREF =#/播放器>播放器和LT; / A>
                    < /李>
                    <立GT;
                        < A HREF =#/俱乐部>俱乐部LT; / A>
                    < /李>
                    <立GT;
                        < A HREF =#/游戏GT&;游戏和LT; / A>
                    < /李>
                < / UL>
            < / NAV>
        < / DIV>
    < /头>
    < D​​IV ID ='contentcontainer'>
        < D​​IV CLASS ='集装箱'NG-视图>< / DIV>
    < / DIV>
< /身体GT;
< / HTML>

lax.js:

  VAR松懈= angular.module('宽松',[]);lax.config(['$ routeProvider',
功能($ routeProvider){
    $ routeProvider。
            当('/家',{
                templateUrl:意见/ news.php',
                控制器:'NewsController
            })。
            当('/球员',{
                templateUrl:意见/ players.php',
                控制器:'PlayersController
            })。
            除此以外({
                redirectTo:'/家
            });
}]);lax.controller('NewsController',函数($范围){
$ scope.message ='这是新增订单屏幕;
});
lax.controller('PlayersController',函数($范围){
$ scope.message ='这是显示屏幕的订单;
});


解决方案

从角1.2.0,ngRoute已经移动到其自己的模块。你必须分装,并声明依赖。

更新HTML:

 <脚本SRC =htt​​ps://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js>< / SCRIPT&GT ;
&所述; SCRIPT SRC =htt​​ps://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-route.js>&下; /脚本>

和JS:

  VAR松懈= angular.module('宽松',['ngRoute']);

有关详细信息:

So I followed this guide: http://viralpatel.net/blogs/angularjs-routing-and-views-tutorial-with-example/

But when I try to change the view nothing happens, anybody a idea what I do wrong?

This is the code I got.Home.php:

<!DOCTYPE html>
<html ng-app="lax">
<head>
    <meta name="author" content="Koen Desmedt" />
    <meta name="description" content="CMS Belgium Lacrosse" />
    <meta name="keywords" content='Lacrosse, BLF, Belgium' />
    <meta name="googlebot" content="noarchive" />
    <link href="lib/bootstrap/css/bootstrap.css" rel="stylesheet">
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>
    <script src="lax.js"></script>
    <link href="css/style.css" rel="stylesheet">
    <title>CMS Belgium Lacrosse</title>
</head>
<body>
    <header class="navbar navbar-inverse navbar-fixed-top bs-docs-nav" role="banner">
        <div class="container">
            <div class="navbar-header">
                <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
            </div>
            <nav class="collapse navbar-collapse bs-navbar-collapse" role="navigation">
                <ul class="nav navbar-nav navbar-left">
                    <li>
                        <a href="#/home">
                            <span class="glyphicon glyphicon-home"></span> BLF
                        </a>
                    </li>
                    <li>
                        <a href="#/players">Players</a>
                    </li>
                    <li>
                        <a href="#/club">Club</a>
                    </li>
                    <li>
                        <a href="#/games">Games</a>
                    </li>
                </ul>
            </nav>
        </div>
    </header>
    <div id='contentcontainer'>
        <div class='container' ng-view></div>
    </div>
</body>
</html>

lax.js:

var lax = angular.module('lax', []);

lax.config(['$routeProvider',
function($routeProvider) {
    $routeProvider.
            when('/home', {
                templateUrl: 'views/news.php',
                controller: 'NewsController'
            }).
            when('/players', {
                templateUrl: 'views/players.php',
                controller: 'PlayersController'
            }).
            otherwise({
                redirectTo: '/home'
            });
}]);

lax.controller('NewsController', function($scope) {
$scope.message = 'This is Add new order screen';
});


lax.controller('PlayersController', function($scope) {
$scope.message = 'This is Show orders screen';
});
解决方案

From angular 1.2.0, ngRoute has been moved to its own module. You have to load it separately and declare the dependency.

Update your html:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-route.js"></script>

And Js:

var lax = angular.module('lax', ['ngRoute']);

For more information: http://docs.angularjs.org/guide/migration

这篇关于AngularJS NG-视图不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 08:32