How to send POST in angularjs with multiple params?

Client Side Data needs to be grouped in an object array as payload – Indata: var Indata = {‘product’: $scope.product, ‘product2’: $scope.product2 }; Pass the payload through $http.post as the second argument: $http.post(“http://localhost:53263/api/Products/”, Indata).then(function (data, status, headers, config) { alert(“success”); },function (data, status, headers, config) { alert(“error”); }); Server Side Create a Data Transfer Object(DTO) … Read more

How to call a function from another controller in AngularJS? [duplicate]

Communication between controllers is done though $emit + $on / $broadcast + $on methods. So in your case you want to call a method of Controller “One” inside Controller “Two”, the correct way to do this is: app.controller(‘One’, [‘$scope’, ‘$rootScope’ function($scope) { $rootScope.$on(“CallParentMethod”, function(){ $scope.parentmethod(); }); $scope.parentmethod = function() { // task } } ]); … Read more

How to autocapitalize the first character in an input field in AngularJS?

Yes, you need to define a directive and define your own parser function: myApp.directive(‘capitalizeFirst’, function($parse) { return { require: ‘ngModel’, link: function(scope, element, attrs, modelCtrl) { var capitalize = function(inputValue) { if (inputValue === undefined) { inputValue=””; } var capitalized = inputValue.charAt(0).toUpperCase() + inputValue.substring(1); if(capitalized !== inputValue) { modelCtrl.$setViewValue(capitalized); modelCtrl.$render(); } return capitalized; } modelCtrl.$parsers.push(capitalize); … Read more

Cordova + Angularjs + Device Ready

Manually bootstrap your Angular app: Remove your ng-app attribute from your HTML code, so Angular doesn’t start itself. Add something like this to you JavaScript code: document.addEventListener(“deviceready”, function() { // retrieve the DOM element that had the ng-app attribute var domElement = document.getElementById(…) / document.querySelector(…); angular.bootstrap(domElement, [“angularAppName”]); }, false); Angular documentation for bootstrapping apps.

How to allow only a number (digits and decimal point) to be typed in an input?

I wrote a working CodePen example to demonstrate a great way of filtering numeric user input. The directive currently only allows positive integers, but the regex can easily be updated to support any desired numeric format. My directive is easy to use: <input type=”text” ng-model=”employee.age” valid-number /> The directive is very easy to understand: var … Read more

if a ngSrc path resolves to a 404, is there a way to fallback to a default?

It’s a pretty simple directive to watch for an error loading an image and to replace the src. (Plunker) Html: <img ng-src=”https://stackoverflow.com/questions/16310298/smiley.png” err-src=”http://google.com/favicon.ico” /> Javascript: var app = angular.module(“MyApp”, []); app.directive(‘errSrc’, function() { return { link: function(scope, element, attrs) { element.bind(‘error’, function() { if (attrs.src != attrs.errSrc) { attrs.$set(‘src’, attrs.errSrc); } }); } } }); … Read more