2017-11-28 34 views
0

프론트 엔드의 arround 각도를 이해하려고합니다. 나는 yeaman 제너레이터를 사용하여 각/꿀꺽 꿀꺽한 프로젝트를 만듭니다.

PS P:\projects\trax> gulp test 
[19:35:22] Using gulpfile P:\projects\trax\gulpfile.js 
[19:35:22] Starting 'scripts'... 
[19:35:30] 
P:\projects\trax\src\app\components\head\user\menu.dialog.controller.js 
    7:9 error "vm" is defined but never used                   no-unused-vars 
    10:5 error You should not set properties on $scope in controllers. Use controllerAs syntax and add data to "this" angular/controller-as 
    14:5 error You should not set properties on $scope in controllers. Use controllerAs syntax and add data to "this" angular/controller-as 
    18:5 error You should not set properties on $scope in controllers. Use controllerAs syntax and add data to "this" angular/controller-as 

✖ 4 problems (4 errors, 0 warnings) 

[19:35:30] all files 14.79 kB 
[19:35:30] Finished 'scripts' after 7.75 s 
[19:35:30] Starting 'test'... 
28 11 2017 19:35:33.855:WARN [proxy]: proxy "\base\src\assets\" normalized to "\base\src\assets\/" 
28 11 2017 19:35:35.077:WARN [watcher]: Pattern "P:/projects/trax/src/**/*.mock.js" does not match any file. 
PhantomJS 1.9.8 (Windows 8 0.0.0): Executed 1 of 1 SUCCESS (0.032 secs/0.34 secs) 
[19:35:38] Finished 'test' after 8.1 s 

그것은 실행하지만 난 LINT 경고를 방지하기 위해 싶습니다

내 문제입니다. 방법? 나는 메시지를 이해하지만 언급대로 대체하면 오류가 발생합니다.

이것은 위에서 언급 한 파일의 코드입니다.

angular 
    .module('trax') 
    .controller('MenuDialogController', MenuDialogController); 

function MenuDialogController($scope, $mdDialog) { 

    var vm = this; 


    $scope.close = function close(){ 
     $mdDialog.hide(); 
    } 

    $scope.cancel = function cancel(){ 
     $mdDialog.hide(); 
    } 

    $scope.ok = function ok(){ 
     alert('ok clicked'); 
     $mdDialog.hide(); 
    } 
} 

그리고 이것은 대화 함수 userController 개방 컨트롤러 ($ 범위, $ mdDialog, $ 문서) {

var vm = this; 

     vm.user = { 
      name: 'Test User' 
     }; 

     vm.showMenu = function showMenu(ev){ 
      $mdDialog.show({ 
       controller: "MenuDialogController", 
       controllerAs: 'vm', 
       templateUrl: 'app/components/head/user/menu.dialog.html', 
       parent: angular.element($document.body), 
       targetEvent: ev, 
       clickOutsideToClose:true, 
       fullscreen: $scope.customFullscreen // Only for -xs, -sm breakpoints. 

      }); 
     }; 
    } 
} 

제가 $ scope.close =로 바와 같은 방법을 변경하면 ... LINT에서 경고를 방지 할 수 있지만 대화 방법은 더 이상 작동하지 않습니다.

모든 힌트 ...? 감사 n00n

답변

0

변경 LINT의 지시에 따라 코드 :

function MenuDialogController($scope, $mdDialog) { 

    var vm = this; 

    ̶$̶s̶c̶o̶p̶e̶.̶c̶l̶o̶s̶e̶ ̶=̶ ̶f̶u̶n̶c̶t̶i̶o̶n̶ ̶c̶l̶o̶s̶e̶(̶)̶{̶ 
    vm.close = function close(){ 
     $mdDialog.hide(); 
    } 

그리고 코드에 맞게 템플릿을 변경 : 대화 컨트롤러는 controllerAS 구문의 인스턴스이기 때문에

<md-dialog-actions> 
    ̶<̶m̶d̶-̶b̶u̶t̶t̶o̶n̶ ̶n̶g̶-̶c̶l̶i̶c̶k̶=̶"̶c̶l̶o̶s̶e̶(̶)̶"̶ ̶c̶l̶a̶s̶s̶=̶"̶m̶d̶-̶p̶r̶i̶m̶a̶r̶y̶"̶>̶C̶l̶o̶s̶e̶ ̶D̶i̶a̶l̶o̶g̶<̶/̶m̶d̶-̶b̶u̶t̶t̶o̶n̶>̶ 
    <md-button ng-click="vm.close()" class="md-primary">Close Dialog</md-button> 
</md-dialog-actions> 

을, 템플리트에는 해당 구문에서 사용되는 ID 인 'vm'이 포함되어야합니다.

+0

thx ... 나는 종종 각도를 찾는 동안 문제를 해결하기 위해 일을 찾습니다. 대부분 나는 그런 작은 것들을 보지 못한다 ... – n00n