首页 新闻 赞助 找找看

angular的$locationProvider和$routeProvider不起作用

0
悬赏园豆:20 [已解决问题] 解决于 2016-10-16 14:05

按照angular-phonecat的代码写了一个简单的记事本,但是基本架构按照phonecat实现却无法出现路由切换功能

默认的时候也没有模板替换,对照代码看了好久也没看出什么原因,基本是照着phonecat实现的

 

新手入门 还请有经验的老鸟可以不嫌弃带一下 因为个人感觉可能是整体架构的问题 所以这里就贴一个github链接 希望可以不嫌麻烦帮忙在本地调试一下 

https://github.com/xiaokk06/guestbook_Angular.git

小kk06的主页 小kk06 | 初学一级 | 园豆:56
提问于:2016-09-12 01:47
< >
分享
最佳答案
0

第一:确认angular和angular-route的版本一致。

 

第二:你的代码有错(你难道没发现控制台有报错么?)

'use strict';

angular.module('list').factory('List', ['$http', function($http) {
    return {
        getItems: $http({
            method: 'GET',
            url: 'php/list.php'
        }).then(function successCallback(response) {
            console.log(response);
            // this callback will be called asynchronously
            // when the response is available
        }, function errorCallback(response) {
            // called asynchronously if an error occurs
            // or server returns response with an error status.
        })
    }

}]);

getItems并不是一个function,至少应该修改为:

'use strict';

angular.module('list').factory('List', ['$http', function ($http) {
    return {
        getItems: function () {
            $http({
                method: 'GET',
                url: 'php/list.php'
            }).then(function successCallback(response) {
                console.log(response);
                // this callback will be called asynchronously
                // when the response is available
            }, function errorCallback(response) {
                // called asynchronously if an error occurs
                // or server returns response with an error status.
            })
        }
    }

}]);

 

收获园豆:20
幻天芒 | 高人七级 |园豆:37175 | 2016-09-12 13:20

我控制台下只看到一个没有请求到图标的错误 0.0 所以没有看到那个错误 我现在去试试是不是你说的这个问题

小kk06 | 园豆:56 (初学一级) | 2016-09-12 13:40

把phonecat目录下面的angular和angular-route文件夹拷贝到app目录下引入发现可以正常运行了 暂时还不知道原因 总之谢谢你的回答 避过了一些坑

小kk06 | 园豆:56 (初学一级) | 2016-09-14 01:27
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册