2016-11-23 3 views
2

웹 서비스에서 매개 변수를 보내는 컨트롤러가 있는데 웹 서비스에서 응답을 받으면 알림을 표시해야합니다 (이것이 내가 notify.js를 사용하는 이유입니다). 그러나 코드가 실행되고 있지 않습니다. . 난 당신을 보여각도 컨트롤러에서 notify.js 사용

컨트롤러 :

$scope.alert = function(){ 
     console.log($scope.q + "/" + $scope.s.id + "/" + $scope.k.id); 
     // http://localhost:8080/test/cftyu/q/q/" + q + k + s 
     return $http.get('http://localhost:8080/test/cftyu/q/q/" + q + k + s) 
     .success(function(data) { 
      return data; 
      console.log(data); 
      $.notify("Hello World"); 
     }) 
     .error(function(data) { 
      return data; 
      console.log(data); 
     }); 
    }; 
    console.log("fin controlador"); 

나는 JQuery와 각도 나는 지침을 만들려고하지 어쨌든 작동하지 불려 통지 알고, 누군가가 나를 도울 수 있기를 바랍니다. 나는 어떤 도움을 주셔서 감사합니다.

편집 : 나는 당신의 솔루션을 시도하고있다

하지만 나에게 작동하지 않습니다 : 솔루션 데이브 쿠퍼 제안하지만 작동하지 않습니다 tryint 내가하고 .

app.controller('CreateQuestionsController', ['$scope', '$log', '$http', '$window', 'sections', 'kind', 'order', 'notify', 
             function($scope, $log, $http, 

    $window, sections, kind, order, notify) { 
    $scope.alert = function(){ 
       return $http.get("http://localhost:8080/test/cftyu/q/q/" + q + k + s) 
       .success(function(data) { 
        console.log(data); 
        notify("Hello World"); 
        return data; 
       }) 
       .error(function(data) { 
        console.log(data); 
        return data; 
       }); 
      }; 
    }]); 

편집 : 2 :

보기 :이 같은 하단의 '주'보기에 모든 JS 파일을로드

<form class="form-horizontal"> 
    <div class="form-group"> 
     <label for="inputEmail3" class="col-sm-2 control-label">Pregunta</label> 
     <div class="col-sm-10"> 
      <textarea class="form-control" rows="3" ng-model="question"></textarea> 
     </div> 
    </div> 
    <div class="form-group"> 
     <div class="col-sm-offset-2 col-sm-3"> 
      <label>Clase</label> 
      <select class="form-control" ng-options="kind as kind.name for kind in kinds track by kind.id" ng-model="kind"></select> 
     </div> 
    </div> 
    <div class="form-group"> 
     <div class="col-sm-offset-2 col-sm-3"> 
      <label>Sección</label> 
      <select class="form-control" ng-options="section as section.sectionname for section in sections track by section.id" ng-model="section"></select> 
     </div> 
    </div> 
    <div class="form-group"> 
     <div class="col-sm-offset-2 col-sm-3"> 
      <button showNotify type="button" class="btn btn-default btn-lg" ng-click="alert()">Guardar</button> 
     </div> 
    </div> 
</form> 

:

나는이 컨트롤러를 가지고 내가

전에 게시처럼
<!-- Modules --> 
    <script src="js/app.js"></script> 

    <!-- Controllers --> 
    <script src="js/controlers/HomeController.js"></script> 
    <script src="js/controlers/CreateQuestionsController.js"></script> 
    <script src="js/controlers/ShowQuestionsController.js"></script> 

    <!-- Services --> 
    <script src="js/services/questions.js"></script> 

    <!-- Directives --> 
    <script src="js/directives/notify.js"></script> 

컨트롤러입니다

편집 3 :

경로 및 컨트롤러도 연결이있다 : 당신은 당신의 알림을 표시하기 전에 당신의 성공 및 오류 함수에서 반환

var app = angular.module('onBuy', ['ngRoute']); 

app.config(function ($routeProvider) { 
    $routeProvider 
     .when('/create/questions/', { 
      controller: 'CreateQuestionsController', 
      templateUrl: 'views/createQuestions.html' 
     }) 
     .otherwise({ 
      redirectTo: '/' 
     }); 
}); 
+0

https://github.com/cgross/angular-notify와 같이 'angular'를 지원하는 라이브러리를 사용하지 않는 이유 –

+0

이 라이브러리를 사용해 보았지만 왜 저에게 효과가 없었는지 모르겠 음 – proktovief

+0

docs가 거기에 제공 –

답변

3

, 그래서 코드의 일부에 도달 할 수 있었다 (즉, 당신은 당신의 데이터를 되돌려 보내고 일을 기록하고 당신의 통지를 보여 주려고했다). 내 코드가 내 말 뜻을 아래에서 볼 수 있습니다.

Angular Notify과 같은 각도 서비스를 사용하는 것이 좋습니다. 여기

은 당신의 코드가 그것으로 어떻게 보이는지 - 당신은 당신의 컨트롤러에 서비스를 주입 한 가정 (I은 샘플 컨트롤러를 포함 시켰습니다) : 도움이

angular.module('app', ['cgNotify']) 
    .controller('myController', function($scope, $http, notify) { 
     $scope.alert = function(){ 
      return $http.get("http://localhost:8080/test/cftyu/q/q/" + q + k + s) 
       .then(function(data) { 
        console.log(data); 
        notify("Hello World"); 
        return data; 
       }, function(data) { 
        console.log(data); 
        return data; 
       }); 
     }; 
     console.log("fin controlador"); 
    }); 

희망!

편집 : 오, 당신도 제공 한 코드에 구문 오류가 있습니다 - 나는 또한 그것을 고쳤습니다!

+0

내가 triyed하지만 여전히 작동하지 않는, 내가 코드를 변경하지만 작동하지 않습니다 – proktovief

+0

내가 게시 한 링크를 triyed하지만 왜 작동하지 않는지 그리고 js 콘솔에 메시지가 표시되지 않음 – proktovief

+0

나머지 코드를 공유 할 수 있습니까? 템플릿을 우리와 공유 할 수 있다면 좋을 것입니다. –