小编nuj*_*bes的帖子

在angular $ http服务中,我如何捕获错误的"状态"?

我正在读一本名为"Pro Angular JS"的书.但是,我有一个关于如何捕获错误状态的问题.

我编码的是:

$http.get(dataUrl)
    .success(function (data){
        $scope.data.products = data;
    })
    .error(function (error){
        $scope.data.error=error;
        console.log($scope.data.error.status); // Undefined!
        // (This is the spot that I don't get it.)                                         
    });
Run Code Online (Sandbox Code Playgroud)

如果我编码"console.log($ scope.data.error.status);" ,为什么console.log的参数未定义?

在书中,有句子,"传递给错误函数的对象定义了状态和消息属性."

所以我做了$ scope.data.error.status

为什么这是错的?

javascript angularjs

47
推荐指数
5
解决办法
11万
查看次数

在Karma Testing中,没有定义ReferenceError:describe

我准备在我的项目中进行单元测试.我写的只是一个简单的测试代码.但是,出现了奇怪的消息:ReferenceError:describe未定义.

我怎么能克服这个?

这是我的代码:

'use strict';

(function() {
    //Cal test Controller Spec
    describe('Cal test Controller Tests',function(){
        //Initialize global variables
        var CalTestController,
            scope;

        //Then we can start by loading the main application module
        beforeEach(module(ApplicationConfiguration.applicationModuleName));

        //The injector ignores leading and trailing underscores here(i.e._$httpBackend_).
        //This allows us to inject a service but then attach to it to a variable.
        //with the same name as the service.
        beforeEach(inject(function($controller,$rootScope){
            //Set a new global scope
            scope=$rootScope.$new();

            //Initialize the Cal test controller.
            CalTestController = $controller('CalController',{
                $scope:scope
            });
        })); …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs karma-jasmine

5
推荐指数
1
解决办法
1万
查看次数

编译器是否提供以下功能:printf,scanf?

我现在正在学习C语言.在本书中,据说"编译器提供了这些库函数:'printf','scanf'......".

我无法理解.那些函数是在头文件中定义的<stdio.h>不是吗?

为什么本书解释了这些函数是由编译器提供的?

c

4
推荐指数
2
解决办法
166
查看次数

标签 统计

angularjs ×2

javascript ×2

c ×1

karma-jasmine ×1