w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Angularjs http.get failure (but I see the data was returned)
It should not be making an OPTIONS request for a GET, so that sounds right. I think what you want to do is: $http.get('http://myserver.com/phones.json').then(function(data) { $scope.phones = data; }, function(err) { alert('Oh no! An error!'}); I think you want to use then(), which takes two functions as arguments — the first for success, and the second for error. $http.get() returns a promise which is acted upon by then(). Also, you probably want to use $resource instead of $http. It provides a higher level of abstraction, and allows for a more reusable style, http://docs.angularjs.org/api/ngResource.$resource EDIT: Check out the angular debug tool here. It shows you what is available in scopes, and shows performance data.

Categories : Javascript

AngularJS: Resolve in RouteProvider - detecting Success / Failure?
You can just return the return value of the then method: resolve: { resolvedData: function(Restangular){ return Restangular.one('Items').get().then(function (data) { ... return successData; // resolvedData will be resolved with the successData }, function () { ... return failureData; // resolvedData will be resolved with the failureData }); } } The then method doc: This method returns a new promise which is resolved or rejected via the return value of the successCallback or errorCallback.

Categories : Angularjs

svn post-commit call to jenkins build http failure
(I assume the "wget wget" in your post-commit file is a typo.) For me your CentOS6 server has some network kernel issues. Right now I am wondering which command prints "failed: Permission denied". I've never seen wget fail like that and it looks more like a local system failure (like open() system call failing). To confirm such an issue, try doing wget to a different address, like google.com, as non root user. Does it work ? Also use strace to find out more. strace wget etc and take note of the failing line. If so, have you compiled your own kernel ? Have you set CONFIG_ADROID_PARANOID_NETWORK to true ? Note: for CSRF protected sites, you need to add extra parameters to download the crumb (this is defined in the Subversion plugin page.

Categories : Svn

Neat ruby way of returning failure or continuing after function call
A bit of DRY maybe? Something like def call_func(_method, arguments) raise "your exception" if send(_method, arguments) == -1 end call_func(:function_call, arguments) call_func(:another_function_call, arguments2)

Categories : Ruby

After Angular.js $http request, call complete function regardless of success or failure of promise
I'm not the world's greatest expert in Angular.js but understand you can do as follows : whatever.then(function() { // success code here }, function() { // error code here return true; // return anything that's not undefined (and not a `throw()`) to force the chain down the success path at the following then(). }).then(function() { // "complete" code here }); You are essentially forced to contrive something from one or more .then(), which is a $q promise's only method.

Categories : Ajax

AngularJS call webmethod
In angular their are different way to achieve this and angular has module for the same Below is the list http://docs.angularjs.org/api/ngResource.$resource http://docs.angularjs.org/api/ng.$http http://docs.angularjs.org/api/ng.$httpBackend You need to inject this module from above, generally people write service for this using factory mehthod below is the example: app.factory('myService', function($http) { return { getList:function(params){ var promise= $http({url: 'ServerURL',method: "POST", params: params}).then(function(response,status){ return response.data; }); // Return the promise to the controller return promise; } } }); app.controller('MainCtrl', function($scope, myService) { myService.getList(fun

Categories : Jquery

Cannot call a certain function twice in AngularJS
You're overwriting the function with the data returned: $scope.messagesIndex = function($groupID){ ... $scope.messagesIndex = data; ... $scope.messagesIndex = data.response; $scope.messagesIndex can't equal a function and the data you receive.

Categories : Function

AngularJS $http not firing get call
Starting from angular 1.1.4 you need to call $http in the context of an angular digest loop. If you do not do so then you can manually call $scope.$apply(); after the http call. See https://github.com/angular/angular.js/issues/2431#issuecomment-18566595

Categories : Javascript

How call ajax from factory in angularjs?
You should use Angulars' $http for making these calls. Ie. var app = angular.module('myApp', []).config(/* config stuff */ ); app.PersonFactory = angular.factory('PersonResource', function($http) { /* your code here */ /* when you want to make Ajax calls, use $http */ $http.get('/some/url/to/persons') .success(function (response) {...}) .error(function(err){...}); /* keep going */ }); Additionally, if your Persons resource is RESTful, you can just use $resource, ie. var app = angular.module('myApp', []).... /* setup app */ app.personsFactory = angular.factory('personsFactory', function($resource) { var persons = $resource('/api/persons/:id', {id: '@id'}); return persons; }); That way angular will know that on your /api/persons url it can GET persons, it can PO

Categories : Jquery

Basic AJAX GET call with AngularJS
Use the $http service rather than $resource. You also wouldn't want to include the extra $resource script/dependency just for that. Simple usage: $http.get('path/here').then(function(response) { console.log(response.data); }); An example of implementing an $http call with good application architecture: Live demo here (click). var app = angular.module('myApp', []); app.factory('myService', function($http, $q) { return { getPage: function(page) { var deferred = $q.defer(); $http.get(page).then(function(response) { deferred.resolve(response.data); }); return deferred.promise; } }; }); app.controller('appCtrl', function($scope, myService) { $scope.page = myService.getPage('test'); });

Categories : Jquery

AngularJS : From a factory, how can I call another function
By doing templates = this.getTemplates(); you are referring to an object property that is not yet instantiated. Instead you can gradually populate the object: .factory('templateFactory', ['$http', function($http) { var templates = []; var obj = {}; obj.getTemplates = function(){ $http.get('../api/index.php/path/templates.json') .success ( function (data) { templates = data; }); return templates; } obj.delete = function (id) { $http.delete('../api/index.php/path/templates/' + id + '.json') .success(function() { templates = obj.getTemplates(); }); } return obj; }]);

Categories : Function

angularJS data not available due to async call
I think you want to look at resolve: http://www.youtube.com/watch?v=Kr1qZ8Ik9G8 This allows you to load all your data before instantiating your controller and firing a routeChangeSuccess event. In the angular docs.

Categories : Javascript

How can I call a service from a template in AngularJS?
Yes, it would be best practice to create a controller. The idea behind the MVC app architecture is that you don't tightly couple your objects/classes together. Injecting a service into a controller, then subsequently your controller adding levels to $scope means that your HTML doesn't have to worry about where it gets the data from. Also, using ng-init in that way is arguably fine for knocking up a very quick prototype, but that approach shouldn't be used in production code (as your model's data itself is tightly coupled to your view's HTML). Tip: It might be a good idea to use a controller for the parent container of your dropdown-menu (ie. the page/section) and then use a directive for your dropdown-menu itself. Think of a directive as a view component. In general, you might find t

Categories : Angularjs

AngularJS set synchronous call of function from directive
$http(...) evaluates to a promise. That means that given var x = $http(...) You can do x.then(function success(){...}, function failure(){...}); and the success or failure function will only be called when the promise is resolved. See the promise API. Your functions can return this x and their calling functions can interact with it as a promise.

Categories : Javascript

JQuery ajax call from angularjs service
1) Send a callback function into the service and when the ajax call from jQuery is complete, call the callback. In the callback you send in, populate the array or call the alert or whatever you need to do. searchService.CallWeb($scope.userName, function(data){ $scope.results = data; }); 2) You can also use an Angular resource to do this. Replace the jQuery ajax call with a resource call and instead of returning the value from the service, return the promise that the resource provides. Then you can use the promise in your controller to take the data and do whatever with it.

Categories : Jquery

AngularJS: Call the ng-submit event outside the form
Here is my test code. The controller who has the login method is already called! <form ng-submit="login()" id="form-test" name="formTest"> <input type="text" name="username"> <br> <input type="password" name="userpass"> <br> <!-- works --> <input type="submit" value="submit inside" id="test"> </form> <!-- change the path from /#/login to /?username=aaa&userpass=aaa#/login and reloads the page--> <button type="submit" onclick="$('#form-test').submit();">submit outside (jquery)</button> <!-- doesn't work --> <button type="submit" ng-click="formTest.submit()">submit outside (ng-click)</button>

Categories : Javascript

Using a Relative Path for a Service Call in AngularJS
Use the $location service - it will return your path, the hash, the server address.. Everything you need! Your call would be to $location.path()+"/GetUserList" or something similar. See here: http://docs.angularjs.org/guide/dev_guide.services.$location

Categories : Javascript

Call angularjs service from simple js code
Use angular.injector. Using your code you can do something like the following: angular.module('main.app', []).factory('MyService', ['$http', function ($http) { return new function () { this.GetName = function () { return "MyName"; }; }; }]); angular.injector(['ng', 'main.app']).get("MyService").GetName(); Here is the jsfiddle: http://jsfiddle.net/wGeNG/ NOTE - You need to add "ng" as your first module before loading your custom module since your example code depends upon $http provider which is in the ng module. EDIT - Using get() as in OP's answer but note this code is fetching the service without relying upon the element being bound to the app module "main.app".

Categories : Javascript

angularjs: using $watch in directive to call serivce
You passed in srv.doStuff(), which is a function call rather than an actually function, you can use one of the following solutions: Warp the function call srv.doStuff() in a function like this link: function (scope, elem, attrs, ctrl) { scope.$watch('var', function () { srv.doStuff(); }, true); } Or simply link: function (scope, elem, attrs, ctrl) { scope.$watch('var', srv.doStuff, true); }

Categories : Javascript

can't call django json view with angularjs
$http.get('http://localhost:8000/myapp/myview/').success(function(data) The URL needs to drop the trailing /, then append .json. Like so: $http.get('http://localhost:8000/myapp/myview.json').success(function(data)

Categories : Django

Prevent AngularJS Controller call if unauthenticated
I suggest you should check authentication on server side and return appropriate message on client side Below is the url help http://www.espeo.pl/2012/02/26/authentication-in-angularjs-application and Write global handler in client side to check it Below is a sample code: angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives'], function ($routeProvider, $locationProvider, $httpProvider) { var interceptor = ['$rootScope', '$q', function (scope, $q) { function success(response) { return response; } function error(response) { var status = response.status; if (status == 401) { window.location = "./index.html"; return; } // otherwise

Categories : Angularjs

how to call parent method with dependencies in angularjs
There are number of unanswered questions here but, like what is the structure of your html ng-controller structure. Also the call sytax in html is wrong for ng-click="go('/item/{{item.id}}') It should be ng-click="go('/item/'+ item.id)" Said that depending on where the ng-click is declared it would have access to parent methods. If you can access a method using $parent then you can access the method directly due to prototypal inheritance. If structure is like <div ng-controller='ParentCtrl'> <div ng-controller='ParentCtrl_2'> <div ng-controller='ChildCtrl'> <!-- ng-click somewhere here --> </div> </div> </div> Then you access the ParentCtrl_2 method go whenever you call. If it is <

Categories : Angularjs

AngularJS $http call not outputting Array
A few issues here. json_encode() from PHP should work, but make sure the header is set correctly. <?php header('Content-type: application/json'); echo json_encode(someFunctionInAnotherFile($_POST['data'])); ?> The second issue is that json_encode will turn a PHP "array" into an object if the array is an "associative" array and a regular array otherwise. Lastly, displaying raw post data is incredibly dangerous and you should not do it.

Categories : Angularjs

AngularJS app using TypeScript cannot call method of undefined
These lines seem almost certainly wrong; what were you intending to do passing the .prototype here? angular.module("mainApp").factory("TokenHandler", () => TokenHandler.prototype); angular.module("mainApp").factory("AuthService", () => AuthService.prototype); I think you want: angular.module("mainApp").factory("TokenHandler", () => new TokenHandler()); angular.module("mainApp").factory("AuthService", () => new AuthService());

Categories : Angularjs

How to use a angularjs route to call a javascript function
If your controller is being used on a particular route, then you can call that function inside the controller. It will get executed once the route changes and your controller is called. In this http://plnkr.co/edit/qUZ5Q7nKCRAS8dFvjRIg when you click on link1 it displays alert. I can't quite catch why your code doesn't work as expected, but I created a similar app setup and it works: var app = angular.module('myApp',[]). config(['$routeProvider',function($routeProvider) { $routeProvider. when('/', { controller: 'PageController', template: '<br><br>this is page #/<br> {{data}}', }). when('/link1', { controller: 'SpecificPageController', template: '<br><br>this is page #/link

Categories : Function

Angularjs function call issue with nested elements
Is there some way to call getCellValue() when the input is updated without calling the method on every instance? <div class="output" ng-bind="foo"> then use $watch: function MyCellCtrl($scope) { $scope.foo = $scope.lw.library.name; $scope.$watch('foo', function(newValue) { $scope.foo = getCellValue($scope.foo); }); } or use viewChangeListeners as an alternative: function MyCellCtrl($scope) { $scope.foo = $scope.lw.library.name; this.$viewChangeListeners.push(function(newValue) { $scope.foo = getCellValue($scope.foo); }); } References Effective Strategies for avoiding watches in AngularJS Compile, Pre, and Post Linking in AngularJS

Categories : Angularjs

AngularJS: model data from http call not available in directive
You are replacing the content of the directive in your directive implementation. Since the $http request is async, the directive completes before the data is retrieve and assigned to the scope. Put a watch on data variable inside the directive and then re-render the content, something like scope.$watch(attrs.source,function(value) { var e = $interpolate(text)(scope); var htmlText = "<b>" + e + "</b>"; element.html(htmlText); }); Based on @Marks feedback and your request i have update fiddle http://jsfiddle.net/cmyworld/V6sDs/1/

Categories : Angularjs

Angularjs model does not render when change in DWR call back
I'm not super familiar with DWR, but my guess is that you need an $scope.$apply to enclose your model change. Like so: function mainCtrl($scope) { $scope.mymodel = "x"; // this is ok DWRService.searchForSomething(function(result){ $scope.$apply(function() { $scope.mymodel = result; // PROBLEM!!! it does not rerender the new value }); }); $scope.mymodel = "y"; // this is also ok. }

Categories : Angularjs

How to pass Rails current_user to AngularJS factory API call?
The user should never be sent from the client. You should never trust the client. Your rails app should have a session, and you should store the current user somewhere in the session. (Session is a hash, if you are doing it manually just use a sensible key to store the current user's ID). You do it on logging in, and just retrieve it afterwards. class ApplicationController < ActionController::Base attr_accessor :current_user before_filter :load_current_user # ... private def load_current_user self.current_user = User.find(session[:user_id]) end end And in your controller: def usersubmission @submissions = current_user.submissions @submission = @submissions.find(params[:id]) render json: @submission end If you use Devise or similar it's much easier an

Categories : Javascript

AngularJS REST async call not returning data
you have to return the promise in your service return $q.all(newsCall, tweetsCall).then(function(values) { var news = values[0].data.results; var tweets = values[1].data.results; var a = doSomeThing(news); var b = doSomeThingToo(tweets); return [a, b]; }); en then in your controller wait for it to resolve: dataService.getNewsAndTweets().then(function(data){ $scope.news = data[0]; $scope.tweets = data[0]; });

Categories : Rest

AngularJS: 'google-maps': call directive in infoWindow
You can try the following: get the latest version of angularjs-ui-maps Use the tempalteUrl property of the directive - you can add your directives inside the template (see how this is done in the example.html that's included in the source). This way you can avoid any custom compilation of html I'd faced a similar problem: AngularJS: using a directive in Google maps marker window In case you find any other approach, please do post it. HTH

Categories : Angularjs

Is it very bad to call a function that locally computes a value from an AngularJS expression?
One option is to set a $watch on the state condition. $watch can take a function parameter and so you can do this: $scope.$watch(function(){ return $scope.prop1 && $scope.prop2 && $scope.prop3; },function(val){ $scope.state = val; }); Here is a minimal demo

Categories : Angularjs

angularjs directive call function specified in attribute and pass an argument to it
Not knowing exactly what you want to do... but still here's a possible solution. Create a scope with a '&'-property in the local scope. It "provides a way to execute an expression in the context of the parent scope" (see the directive documentation for details). I also noticed that you used a shorthand linking function and shoved in object attributes in there. You can't do that. It is more clear (imho) to just return the directive-definition object. See my code below. Here's a code sample and a fiddle. <div ng-app="myApp"> <div ng-controller="myController"> <div my-method='theMethodToBeCalled'>Click me</div> </div> </div> <script> var app = angular.module('myApp',[]); app.directive("myMethod",function($parse) { var direc

Categories : Angularjs

AngularJS : Call a Controller Function from a directive without isolated scope
explictly call hideButton on the parent scope here's the fiddle: http://jsfiddle.net/pXej2/5/ and here is the updated HTML <div ng-app="myModule" ng-controller="myController"> <input ng-model="showIt"></input> <button ng-hide="$parent.hideButton()" confirm="Are you sure?" confirm-action="doIt()">Do It</button> </div>

Categories : Angularjs

AngularJS Bind Data returned from Async Call in ngrepeat
This worked for me: Binding variables from Service/Factory to Controllers Also watching the videos at egghead.io helped a ton (http://www.egghead.io/lessons)

Categories : Angularjs

What is the correct architectural pattern for cross domain REST call in AngularJS?
You need to go into Remote Settings within SalesForce then CORS and whitelist the domain name... I had the same issue and it seemed to have resolved the issue. See if this helps here

Categories : Angularjs

AngularJS evaluate a string in a function to call property on json list
If I understand correctly: $scope.moveUser = function(fromId, toId, index) { if (users.hasOwnProperty(fromId) && users.hasOwnProperty(toId)) { scope.users.toId.list.push(scope.users.fromId.list[index]); scope.users.fromId.list.splice(index, 1); return true; } else { return false; } };

Categories : Javascript

In ASP.NET is there an event fired on a Windows Authentication log in failure? (Logging the details of a Windows Authentication failure)
I was looking at the same issue, and looks like there is no events for windows authentication, even that Authenticate event is common for forms and windows. But I found a solution to this! http://www.codeproject.com/Articles/11202/Redirecting-to-custom-401-page-when-quot-Access-de UPDATE From original article protected void Application_EndRequest(Object sender, EventArgs e) { HttpContext context = HttpContext.Current; if (context.Response.Status.Substring(0,3).Equals("401")) { if(User.Identity.IsAuthenticated) { // this means user is authenticated, but 401 still returned // which means no access to page or whatever you are trying to access? } } } UPDATE2 I also found out that this solution doesn't work in all cases. I was testing in different envir

Categories : Asp Net Mvc

AngularJS promise doesn't retrieve a deeply wrapped jquery $.post call
The first thing to try is fixing this call: var promise = Data.getColNamesFromDb("table1", $scope); According to your example, that method is defined as taking $scope as the first parameter, not the second, so your safeApply function will never actually cause a $digest cycle to occur since that string doesn't have a $$phase property. Edit Now that the example has been corrected, try this: angular.module( "app" ).service( "Data", function( $q ) { return { getColNamesFromDb: function( table, scope ) { var deferred = $q.defer(); function safeApply( fn ) { if ( !scope.$$phase ) { scope.$apply( fn ); } else { fn(); } } queryW

Categories : Jquery

Angularjs How do you call a controller method inside a javascript function defined in the html template file?
I figured it out with help from a friend. Here is the solution: in the signin.html file add an id to the div at the top. In the script code use that id to get to the scope using jquery (you don't need to use the angular.element()). signin.html <div id="loginwidget"> <div role="main" id="content" > <div id="signIn" > </div> <div> <div> <script> $.ready('loginwidget_main', function () { loginwidget.load('signin', function () { done : success, fail : fail }); }); function success() { var scope = $('#loginwidget').scope(); scope.test(); } function fail() {alert("failed to login");} </script>

Categories : Angularjs



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.