我有一个控制器向Web服务发送参数,当我得到Web服务的响应时,我必须显示一个通知(这就是为什么我使用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:
查看:
<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>
我加载在 '主' 视图中的所有js文件,在这样的底部:
<!-- 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: '/'
});
});
为什么你不使用类似https://github.com/cgross/angular-notify支持'angular'的库 –
我试过这个库,但不知道为什么不能为我工作 – proktovief
只是试着根据提供那里的文档 –