小编Bja*_*rki的帖子

用.success()获取'未定义'的Karma测试不是一个对象'

我正在尝试编写一个单元测试,看看如果适当设置某些属性,我的控制器中的'getStudents()'提供程序函数是否会被调用.注意.success()回调:

 $scope.update = function update() {
    // omitted, just doing some checking...
    // finally 
    else if (key.length === 3 || $scope.students.length === 0) {
       StudentsProvider.getStudents($scope.keyword, $scope.selectedFilters).success(function(data) {
           $scope.students = data;
       });
    }
 };
Run Code Online (Sandbox Code Playgroud)

我的业力单元测试看起来像这样:

describe("Students: Controllers", function () {
    var $scope;
    var ctrl;
    beforeEach(module('studentsApp'));

    describe("SearchCtrl", function () {
        // Mock the provider
        var mockStudentsProvider = {
            getStudents: function getStudents() {
                return [
                    {
                         Education: [], 
                         Person: [{ 
                             ID: 1, 
                             Name: "Testing McTestsson", 
                             SSN: "1234567890",
                             Address: "Fakestreet 3", MobilePhone: "7777777"
                         }] …
Run Code Online (Sandbox Code Playgroud)

unit-testing angularjs karma-runner

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

Angular指令数据绑定无法正常工作

我一直在尝试为我的角度应用程序编写一个共享指令,将输入字段转换为jquery timepicker.

我有两个输入字段,fromTime和toTime,我想在更改fromTime时更新toTime.

我的代码如下:

HTML

<input type="text"
       time-picker="{ timeFormat: 'H:i'}"
       class="input-block-level"
       name="fromTime"
       ng-model="filter.fromTime"
       ng-change="update()" 
/>

<input type="text"
       time-picker="{ timeFormat: 'H:i'}"
       class="input-block-level"
       name="toTime"
       ng-model="filter.toTime"
       ng-change="update()" 
/>
Run Code Online (Sandbox Code Playgroud)

指示

sharedServices.directive('TimePicker', function () {
return {
    restrict: 'A',
    scope: {
        time: "=ngModel"
    },
    link: function(scope, element, attrs) {
                    //Initialize the timepicker
        $(element).timepicker(scope.$eval(attrs.TimePicker));
                    //watch for changes
        scope.$watch('time', function(stuff) {
            console.log('some change', stuff);
        });
    }
};
});
Run Code Online (Sandbox Code Playgroud)

包括sharedServices

var roomsApp = angular.module("roomsApp", ["ngResource",'ui', 'sharedServices','ui.bootstrap']).config(function($routeProvider) { ...
Run Code Online (Sandbox Code Playgroud)

指令加载和timepicker初始化并附加到元素,但是当我更改输入字段时没有任何反应,甚至连元素附加的ng-change事件也没有.页面加载时输入字段也为空,即使模型设置为在应用程序的控制器中包含某些值.谁能解释一下这个问题呢?

*更新 http://plnkr.co/edit/t3BzShezEdh29ZAlI8ZI?p=preview这证明了我的问题.更改日期时,没有任何控制台记录

html javascript angularjs angularjs-directive

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