Search Posts

Category: controller

Detect hit to back history in angular

how to Detect hit to back history in angular I did this below to detect back button hit to previous page, but the detection is working fine, my headache is that the app run functions variable $rootScope.$rootScope.UseInController don’t pass the data once to controller. Here is the script. App.run(function($rootScope, $location, $route){ $rootScope.$on(‘$locationChangeSuccess’, function() { $rootScope.actualLocation = $location.path(); }); $rootScope.$watch( function() { return $location.path(); }, function(newLocation, oldLocation){ if($rootScope.actualLocation === newLocation) { alert(‘You go back to previous […]

AngularJS: Some form fields not bound with viewmodel

I’m writing a form that binds inputs with a angularJS model. For some reason, only certain fields are bound to the model (vm.customer). For example, vm.last_name, and vm.email are bound. But vm.first_name and vm.gender are not bound from inputs to model. /* AddCustomer.js */ (function (angular) { ‘use strict’; angular.module(‘app’, []); function controller($scope) { var vm = this; vm.genders = [“Male”, “Female”, “Other”]; vm.customer = { first_name: ‘Susan’, last_name: ‘BOyle’, email: ‘[email protected]’, ip_address: ‘192.168.1.120’, gender: […]

Angular $http post not returning Json response

Recipes/CreateRecipe was successful but return Json is not returning anything and goes to the next function which is the alert Error CreateRecipe null script $scope.createRecipe = function (recipe) { $http({ method: ‘POST’, url: ‘/Recipes/CreateRecipe’, data: JSON.stringify(recipe) }).then(function (response) { if (response!=null) { $scope.recipeID = response.data; alert($scope.recipeID) } else { alert(“get response failed! ” + response.data) } }, function (response) { alert(‘Error CreateRecipe ‘+response.data); }); }; controller [HttpPost] public JsonResult CreateRecipe([Bind(Include = “Id,Name”)] Recipe vm) { […]

AngularJS controller can not inject resolver

Please see this fiddle I want to inject resolver into the AngularJS controller but not working. The error message is Unknown provider: urlParasProvider <- urlParas <- MyController Any suggestions, thanks! function config($routeProvider){ $routeProvider .when(‘/abc’,{ controller: ‘MyController’, resolve: { urlParas : function(){ // return $location.absUrl(); return ‘abc’; } } }) .otherwise({ controller: ‘MyController’, resolve: { urlParas : function(){ // return $location.absUrl(); return ‘abc’; } } }); } myApp.$inject = [‘$scope’,’urlParas’]; Source: AngularJS

How to extract response body from Angularjs CacheFactory

I am new to Angularjs and trying to learn cachefactory. I am having trouble reading the response data using cachefactory. As of now I am just trying to print it on console immediately after calling the rest api. My javascript controller is: (function() { “use strict”; angular .module(“productManagement”) .controller(“WelcomeCtrl”, [ ‘$scope’, ‘$http’, ‘$timeout’, “$interval”, “$cacheFactory”, WelcomeCtrl ]) function WelcomeCtrl($scope, $http, $timeout, $interval, $cacheFactory) { var onUserComplete = function(response) { $scope.fname = response.data.firstName; console.log(“response.firstName:”+response.data.firstName); var $httpDefaultCache […]

AngularJs setDirty in Controller

I’m trying to set some fields to dirty after a specific button is clicked. template <div class=”col-md-4″> <label class=”radio radio–inline”> <input type=”radio” class=”radio__control” name=”radio_Role”ng-model=”Form.RoleCheck” value=”1″ required> <span class=”radio__label”> Whatever </span> </label> </div> <button id=”gotoPersonendatenVn” ng-click=”dirty()” type=”button”> Dirty </button> app.js $scope.dirty = function(){ $scope.Form.RoleCheck.$setDirty(); } I’ve tried different things but i always get “TypeError: $scope.Form.RoleCheck is undefined” Source: AngularJS

how to give controller a name in a directive in Angular

So it might be a simple question. I have a directive defined this way: angular .module(‘ui-abc’, [ ‘xyz’]) .directive(‘computer’, compute); function compute( item) { return { restrict: “EA”, templateUrl: ‘../elements/src/template.html’, scope:{ qwerty : ‘=’,} controller: [‘$scope’,’$sce’, { ……… } The controller does not have a name, how can i add one ? I need this name so that I can refer to that controller inside my ui-router configuration. I tried to do this function compute( […]

Angularjs $http spring rest controller – 404 error

I am getting 404 error on making a $http call from angularjs to spring controller, here is the code : Factory : factory.checkCodeAvail = function(url){ return $http({ url: url, responseType:”json”, method: “GET”, headers: { “Content-Type”: “application/json” } }); } This factory method is called by controller : commonFactory.checkCodeAvail(‘findDepartment’) .then(function (success){ console.log(success); },function (error){ console.log(error); }); This is the error i m getting in browser console : GET http://localhost:8080/TexERP/findDepartment 404 () Spring controller : @RestController public […]

Angularjs Google Map API Integration

I’m trying to add a google map in angular JS… and have been struggling. I didn’t want to use one of the angular dependencies, but simulate the ‘async defer’ on the Google JS API site. I’m pretty new to Angularjs but get the concept of keeping things assigned to the controllers scope. Pretty sure it’s just something dumb, but not sure what… any help would be awesome 🙂 (function () { ‘use strict’; app.controller(‘travelCtrl’, [‘$scope’, […]

Next Page »