angularjs-scope

Cannot read property push of null

半世苍凉 提交于 2020-01-14 07:49:07
问题 while pushing an element for the first time to a child array which is null,I'm getting this error "Cannot read property push of null" But the element gets pushed,and the second time I do everything goes fine.It gets added to the array this.group.departmentsList.push({ name: group.newCategoryName, sortOrder: group.departmentsList.length, type: "category" }); group contains the data and departmentList is the child array which is declared like this: $scope.parentDepartment = [ { departmentsList:

AngularJS: Sharing scope between multiple instances of same directive

旧巷老猫 提交于 2020-01-14 04:47:06
问题 I'm writing an app that uses the same table with the same data in multiple places. I created a custom directive that allows me to reuse this table. Unfortunately, if I edit the table in one instance, the other instance does not refresh. How do I link these two so that any edits I make to one show up in the other? 回答1: It sounds like you've mostly figured it out, the hard part is getting your data into a shape where the videos and photos can be shared by the slide show. I recommend doing this

How to get the index of an parent scope array/ng-repeat inside child ng-repeat

人盡茶涼 提交于 2020-01-11 14:26:09
问题 I am building a table and I have two ng-repeat for my table. My question is if it's possible the child of the ng-repeat can get the parent ng-repeat 's index. For example: <tbody> <tr ng-repeat="company in companies"> <td ng-repeat="product in company"> company # = {{the company index}} and product {{$index}} </td> </tr> </tbody> I am not sure how to add the company index under the td ng-repeat . Is there a way to do this? Thanks a lot! 回答1: This is exactly where ng-init comes into picture,

AngularJS $promise then() data undefined

佐手、 提交于 2020-01-11 02:27:23
问题 I am trying to get data assigned to a $scope variable. Inside my $promise.then() function it is displaying correctly but outside the function it shows as undefined. The following is my controller code: angular.module('testSiteApp').controller('TestController', function ($scope, Tests) { $scope.test = Tests.get({id: 1}); $scope.test.$promise.then(function(data) { $scope.tasks = data.tasks; console.log($scope.tasks); }); console.log($scope.tasks); }); The results inside the then() function:

AngularJS $promise then() data undefined

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-11 02:27:06
问题 I am trying to get data assigned to a $scope variable. Inside my $promise.then() function it is displaying correctly but outside the function it shows as undefined. The following is my controller code: angular.module('testSiteApp').controller('TestController', function ($scope, Tests) { $scope.test = Tests.get({id: 1}); $scope.test.$promise.then(function(data) { $scope.tasks = data.tasks; console.log($scope.tasks); }); console.log($scope.tasks); }); The results inside the then() function:

Getting $parent.$index inside a custom directive

。_饼干妹妹 提交于 2020-01-10 06:14:26
问题 <li ng-repeat="value in array1 track by $index"> <div ng-repeat="j in array2"> <div example-directive > <p> {{$index}} ,{{$parent.$index}}</p> </div> </div> </li> In the above code I couldnt access parent ng-repeat index inside my custom directive.how can I get the index of parent ng-repeat 回答1: This sample can helps you to figure out how can get index or etc ... in directives. var app = angular.module("app", []); app.controller("controller", function ($scope) { $scope.array1 = [ {id: "1-1"},

AngularJS - accessing ng-click in custom directive

邮差的信 提交于 2020-01-10 02:30:07
问题 I'm trying to get my head around directives, i can easily use the template function to throw out my HTML, however, if i have an ng-click within my template, how can i access it within the link function? My directive: app.directive('directiveScroll', function () { return { restrict: 'AE', replace: 'true', template: '<div class="scroll-btns">' + '<div class="arrow-left" ng-click="scrollLeft(sectionID)"></div>' + '<div class="arrow-right" ng-click="scrollRight(sectionID)"></div>' + '</div>',

Getting select rows from ng-grid?

旧城冷巷雨未停 提交于 2020-01-09 19:52:47
问题 How do I create (or access) an array of selected rows in my ng-grid? Documentation (scroll to "Grid options") id | default value | definition ----------------------------------------------- selectedItems | [] | all of the items selected in the grid. In single select mode there will only be one item in the array. index.html <body ng-controller="MyCtrl"> <div class="gridStyle" ng-grid="gridOptions"></div> <h3>Rows selected</h3> <pre>{{selectedItems}}</pre> </body> main.js var app = angular

AngularJs broadcast repeating execution too many times

好久不见. 提交于 2020-01-09 08:35:49
问题 Inside one of my Angular controllers, I have this: // controller A $rootScope.$on("myEventFire", function(event, reload) { someAction(); }); In another controller I have this: // controller B $scope.openList = function(page) { $rootScope.$broadcast('myEventFire', 1); } Now, this is a single-page app. When I go to controller A initially and try triggering this event, someAction() is going to be executed once. If I navigate away and come back again to controller A and do the same thing,

Access Parent Scope in Transcluded Directive

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-09 04:38:33
问题 I would like to access a parent directive's scope, but I can't seem to get the right combination of settings. Is this possible and is it the right approach? I really want to avoid putting something like SOME_CONST (which would help me make DOM updates through control flow) in MyCtrl <div ng-controller="MyCtrl"> <parent> <child></child> </parent> </div> var myApp = angular.module('myApp',[]); function MyCtrl($scope) { $scope.obj = {prop:'foo'}; } myApp.directive('parent', function() { return {