Search Posts

Category: angularjs-scope

Angular JS dynamic model in directive [duplicate]

This question already has an answer here: How to add ng-model functionality to a component 2 answers It can be hard to explain, but will try: I have a directive which consists of textbox + button, and updating scope variable (dynamically or by button click). Directive has two parameters: scope: { bindModel: ‘=ngModel’, /*object | model to update*/ autoBind: ‘=’ /*bool | auto bind input to bindModel or by btn click*/ } Autobind parameter decide […]

AngularJs 1.6 – Parent scope not accessible in directive ‘link’ function

I have hosted my sample app here I am trying to access MainCtrl variable into directives ‘link’ function but getting below error. angular.js:14700 ReferenceError: testMessage is not defined at Object.link (TestDirective.js:12) at angular.js:1385 at invokeLinkFn (angular.js:10545) at nodeLinkFn (angular.js:9934) at angular.js:10273 at processQueue (angular.js:17051) at angular.js:17095 at Scope.$digest (angular.js:18233) at Scope.$apply (angular.js:18531) at done (angular.js:12547) “<test-directive>” I have created angular app using requirejs. ————main.js—————– require.config{ ///configuration here… }); require([‘app’,’angular’,’MainCtrl’,’TestDirective’],function(app,angular){ angular.bootstrap(document,[‘MyApp’]); }); —————app.js————- define([‘angular’,’angular-resource’],function(angular){ var ngapp […]

Angular JS-Storing the row wise table values into the database

I have this situation: I need to bring-up a table structure into a HTML page.One of the columns in this table has to be brought from a table stored in the database.This column value along with two check boxes values needs to be stored in a database and next time these stored values should be brought in ,next time we open that page HTML code: <label class=”col-md-3″ for=”Documents”>Test:</label> <div class=”col-md-8″ ng-controller=”checklistController” ng-init=’populateChecklist()’> <div class=”table-responsive”> <table […]

Angular $digest cycle refreshes the entire view instead of a portion

I am facing a strange issue in Angular 1 which is causing the script to go into infinite loop and eventually the browser hangs. Here is what I am trying to do <script> $scope.A = true; $scope.B = [{blah},{blah}]; $scope.updateB = function(){ $scope.B.push({blah}); } $scope.D = function(key){ $scope.A = false; return key.name; } </script> <div ng-if=”A”> <button ng-click=”updateB()”></button> </div> <div ng-repeat=”key in B”> {{D(key)}} </div> So basically I want to hide first div after the […]

Directive can’t invoke factory after reloading the page in Angular Js?

I am calling factory from directive, But scope is not persist after reloading the page. When I login with my application then It is working fine but when I reload the page Then scope is lost. I am sharing my directive and factory code. Directive “use strict”; angular.module(‘app.auth’).directive(‘loginInfo’, function(User){ return { restrict: ‘A’, templateUrl: ‘app/auth/directives/login.tpl.html’, link: function(scope, element){ User.initialized.then(function(){ scope.user = User }); } } }) Factory ‘use strict’; angular.module(‘app’).factory(‘User’, function ($http, $q, APP_CONFIG,Rh,$rootScope,RhAuth,$location) { […]

forEach not hitting last index’s

Hello I’m looping through an array within my Angular Controller and passing a Promise function to each value, then dynamically creating a $scope module for each one labeled “$scope[‘index_0]” for example. app.controller(‘arrCtrl’, function($scope, dataService){ var catList = <%-JSON.stringify(myCats)%>; var sequence = Promise.resolve(); catList.forEach(function(catObj, index){ sequence = sequence.then(function(){ return dataService.getItemsByCategory(catObj._id); }).then(function(result){ //Create and set scope module to Items array $scope[‘items_’+index] = result; }).catch(function(err){//catch any error console.log(err + ‘ failed to load!’); }); }); console.log(“Controller loaded”); }); […]

angularJS basics struggling – controllers

im new to AngularJS and im having trouble creating a controller for my page its a simple page that load app.js file that has $scope.name = “james”; and i use the expression {{ $scope.name }} to display that value which isnt coming up.. but when i run {{ 2 + 4 }} it shows 6 so angular is working.. another thing is when i open the page in safari the expressions are being displayed raw […]

Methods of saving user info in AngularJS

I want to know about the ways of saving user info. Many seniors have recommended using $cookieStore, or Authentication or etc. But how about using $rootScope? My idea is when user has logged in, saving his/her id and password into $rootScope. (Naming like $rootScope.user_id = ‘stupid’;) Is this dangerous way? I don’t know whether this question is duplicated or not, but I couldn’t find one talking about using $rootScope. . . UPDATE My config is […]

How to edit a scope in angularjs?

I’m trying to figure out how to edit a scope, i can successfully add and remove a object, in this example im developing a simple todo app. I was following this tutorial i referenced a similar question on this site, but nothing similar to what im looking for How do you edit a scope ? <!DOCTYPE html> <html ng-app=”eli”> <head <meta charset=”UTF-8″> <title>Untitled Bullcrap</title> <script src=”https://ajax.googleapis.com/ajax/libs/angularjs/1.6.6/angular.min.js”></script> <script src=”main.js”></script> </head> <body> <div ng-controller=”mycontroller”> <ul> <li ng-repeat […]

How do I reference and set all scope variables created from ng-click within ng-repeat?

I want to be able to hide the item.value when I click on item.label or just hide everything with I click on the button. I’m not too sure how the “hide” variables are related here. From what I understand, they are created separately in an isolated scope so my button should not work. What is the solution here? <button ng-click=”hide=false”>HideAll</button> <div ng-repeat=”item in items”> <div ng-click=”hide=!hide”>item.label</div> <div ng-hide=”hide”>item.value</div> </div> Source: AngularJS

Next Page »