I have a controller sending parameter to a web service, when I get the response from web service I must show a notification (that's why I use notify.js), but the code is not running. I show you:
Controller:
$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");
I hope anyone could help me, I know notify is called with jquery not angular I been trying to create a directive but isn't working anyway. I will appreciate any help.
Edit: I been tryint the solution Dave Cooper proposed but it's not working:
I'm trying your solution but it's not working to me. I've got this controller:
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;
});
};
}]);
Edit 2:
View:
<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>
I load all the js files on the 'main' view, at the bottom like this:
<!-- 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>
The controller is like I posted before
Edit 3:
There is the routes and controller-view connection:
var app = angular.module('onBuy', ['ngRoute']);
app.config(function ($routeProvider) {
$routeProvider
.when('/create/questions/', {
controller: 'CreateQuestionsController',
templateUrl: 'views/createQuestions.html'
})
.otherwise({
redirectTo: '/'
});
});
angularlike github.com/cgross/angular-notify