2014-11-04 32 views
7

我一直在使用1.3的測試版本,現在轉到1.3.1後我發現一個問題,通過檢查所有早期版本,我發現它似乎已經開始在1.3 .0 rc1ngChange在1.3.0之後<select>的問題rc0

我有這樣的代碼:

<select ng-model="home.modal.topicId" 
     ng-change="ctrl.modalTopicChanged()" 
     ng-options="item.id as item.name for item in home.modal.option.topics.data" 
     ng-required="true"> 
     <option style="display: none;" value="">Select Topic</option> 
</select> 

此前RC1的NG-變化是不被解僱當表單是首先顯示。現在它正在被解僱,有一個home.modal.topicId undefined。這對我來說是一個突破性的改變,但它在突破性改變部分沒有提及,我想知道這是一個還沒有被注意到的錯誤。

這裏是產生的堆棧跟蹤:

TypeError: Cannot read property 'dataMap' of undefined 
    at AdminProblemController.modalTopicChanged (http://127.0.0.1:17315/Content/app/admin/controllers/ProblemController.js:109:114) 
    at $parseFunctionCall (http://127.0.0.1:17315/Scripts/angular.js:11387:18) 
    at Scope.$get.Scope.$eval (http://127.0.0.1:17315/Scripts/angular.js:13276:28) 
    at http://127.0.0.1:17315/Scripts/angular.js:19888:13 
    at http://127.0.0.1:17315/Scripts/angular.js:19499:9 
    at forEach (http://127.0.0.1:17315/Scripts/angular.js:331:20) 
    at $$writeModelToScope (http://127.0.0.1:17315/Scripts/angular.js:19497:5) 
    at writeToModelIfNeeded (http://127.0.0.1:17315/Scripts/angular.js:19490:14) 
    at http://127.0.0.1:17315/Scripts/angular.js:19484:9 
    at validationDone (http://127.0.0.1:17315/Scripts/angular.js:19420:9) 

我發現這裏是一個新的功能:writeToModelIfNeeded

當我看到在更改日誌中的差異我無法找到此功能的任何提及引入當我檢查所有更改和行號。

我想獲得一些建議。首先,有可能找到導致添加writeToModelIfNeeded的更改,其次是選擇框的正確功能。我認爲整個想法是隻有模型值被定義時,ng變化纔會發生。

僅供參考下面是新的代碼,似乎已經加入1.3.0 RC.1

** 
    * @ngdoc method 
    * @name ngModel.NgModelController#$commitViewValue 
    * 
    * @description 
    * Commit a pending update to the `$modelValue`. 
    * 
    * Updates may be pending by a debounced event or because the input is waiting for a some future 
    * event defined in `ng-model-options`. this method is rarely needed as `NgModelController` 
    * usually handles calling this in response to input events. 
    */ 
    this.$commitViewValue = function() { 
    var viewValue = ctrl.$viewValue; 

    $timeout.cancel(pendingDebounce); 

    // If the view value has not changed then we should just exit, except in the case where there is 
    // a native validator on the element. In this case the validation state may have changed even though 
    // the viewValue has stayed empty. 
    if (ctrl.$$lastCommittedViewValue === viewValue && (viewValue !== '' || !ctrl.$$hasNativeValidators)) { 
     return; 
    } 
    ctrl.$$lastCommittedViewValue = viewValue; 

    // change to dirty 
    if (ctrl.$pristine) { 
     ctrl.$dirty = true; 
     ctrl.$pristine = false; 
     $animate.removeClass($element, PRISTINE_CLASS); 
     $animate.addClass($element, DIRTY_CLASS); 
     parentForm.$setDirty(); 
    } 
    this.$$parseAndValidate(); 
    }; 

    this.$$parseAndValidate = function() { 
    var parserValid = true, 
     viewValue = ctrl.$$lastCommittedViewValue, 
     modelValue = viewValue; 
    for(var i = 0; i < ctrl.$parsers.length; i++) { 
     modelValue = ctrl.$parsers[i](modelValue); 
     if (isUndefined(modelValue)) { 
     parserValid = false; 
     break; 
     } 
    } 
    if (isNumber(ctrl.$modelValue) && isNaN(ctrl.$modelValue)) { 
     // ctrl.$modelValue has not been touched yet... 
     ctrl.$modelValue = ngModelGet(); 
    } 
    var prevModelValue = ctrl.$modelValue; 
    var allowInvalid = ctrl.$options && ctrl.$options.allowInvalid; 
    if (allowInvalid) { 
     ctrl.$modelValue = modelValue; 
     writeToModelIfNeeded(); 
    } 
    ctrl.$$runValidators(parserValid, modelValue, viewValue, function() { 
     if (!allowInvalid) { 
     ctrl.$modelValue = ctrl.$valid ? modelValue : undefined; 
     writeToModelIfNeeded(); 
     } 
    }); 

    function writeToModelIfNeeded() { 
     if (ctrl.$modelValue !== prevModelValue) { 
     ctrl.$$writeModelToScope(); 
     } 
    } 
    }; 

    this.$$writeModelToScope = function() { 
    ngModelSet(ctrl.$modelValue); 
    forEach(ctrl.$viewChangeListeners, function(listener) { 
     try { 
     listener(); 
     } catch(e) { 
     $exceptionHandler(e); 
     } 
    }); 
    }; 
+0

您是否嘗試過創建的jsfiddle與一個1.2x和1.3x的切換? – John 2014-11-06 17:27:08

+3

我無法複製此問題,** [請參閱此搶注者](http://plnkr.co/edit/KMIOZx7pV4OYmhk1XayE?p=preview)**。你介意分享這個重新編譯這個問題的修改版本嗎?謝謝! – Josep 2014-11-07 02:41:03

+0

我會研究這個問題,看看我能否找到這個實現和我的區別。謝謝 – 2014-11-07 14:54:16

回答

5

我能夠這樣做是爲了重現您的問題的區域。沒有看到你的控制器,雖然不知道,如果同樣的事情:

this.modal = { 
     topicId:null, 
     option:{ 
     topics:{ 
      data:[{id:1,name:'item1'},{id:2,name:'item2'}] 
     } 
     } 
    }; 

這到底是怎麼發生的是角度說,零是一個無效的值,因此在默認情況下將其設置爲undefined。你可以將其設置爲「未定義」或添加給你的HTML解決這個問題:

ng-model-options="{allowInvalid:true}" 

還測試了何塞普plunker和改變該值也爲空造成ngChange火