angularjs-scope

Bind an externally loaded DOM element to Angular's scope

不想你离开。 提交于 2019-12-06 16:37:44
I'm using Google Maps within an Angular app. As per Google Maps's API, I pass a string to a google.maps function containing HTML, and the library displays it on the map as an InfoView. I'm adding a button to this view, and I want this view to be bound to a controller in my Angular app, however, even if I pass <div ng-controller="MyController">...</div> , when the Maps library attaches it to the DOM, Angular is not notified. How can I force the compilation of this element (over which I have very little control: just passing a string)? For AngularJS to "notice" the directive, it'd need to

Referencing the element that's calling a controller function Angularjs

蓝咒 提交于 2019-12-06 15:59:08
问题 Fairly simple but I can't figure out the term I need to google. How do I reference whichever element is calling the controllers blurr function? html <body ng-app="test"> <div ng-controller="Cntrlr as cntrlr"> <input type="text" ng-model="cntrlr.inpt" ng-blur="cntrlr.blurr()" /> <input type="text" ng-model="cntrlr.second" ng-blur="cntrlr.blurr()" /> </div> </body> js var app = angular.module("test", []); app.controller("Cntrlr", ["$scope", function($scope){ this.blurr = function(){ alert(

Pass variable to UI-bootstrap modal without using $scope

余生颓废 提交于 2019-12-06 15:54:36
Since I am a beginner using AngularJS the $scope approach to pass data between different controllers and (in my case) a modal drives me crazy. Due to that reason, I googled around the web and found an interesting blogpost about passing data to a UI-bootstrap modal without using $scope . I had a deeper look at this blogpost and the delivered plunk which works pretty nice and started to adopt this to my own needs. What I want to achieve is to open a modal delivering an text input in which the user is able to change the description of a given product. Since this would provide more than a minimal

Show image / background on md-select / md-options on hover in AngularJS 1.6

折月煮酒 提交于 2019-12-06 15:43:42
I'm trying to put a hover on AngularJS material md-select dropdown where in on hover it shows a image next to it in a div / span . I'm unising the below code but still it's not coming: <md-select id="{{mapping.id}}" ng-model="mapping.value"> <md-option ng-value="option" ng-mouseenter="show = true" ng-mouseleave="show = false" ng-repeat="map in mapping.values" ng-selected="$first">{{maping.options[$index]}}</md-option> <span ng-show="show"> <img src="{{mapping.image[$index]}}" align-"right" width="60px" height="40px" vertical-align="top"/> </span> </md-select> and using the below in app: scope

angularjs form can not refer to input control when input name is array

若如初见. 提交于 2019-12-06 14:29:30
问题 I encounter a problem when testing form validation with angularjs According to angularjs form guide, an input control that has the ngModel directive holds an instance of NgModelController. Such a control instance can be published as a property of the form instance using the name attribute on the input control. I created test code at plunker, it all works fine untill I change the input name from <input type="number" name="age" ng-model="user.age" max="100" required> <p>{{form1.age.$error}}</p>

Angularjs; use $http in service returns reference instead of actual data

别来无恙 提交于 2019-12-06 12:31:43
I'm using the services directive in Angularjs not factory and I need to populate a json file to local variable; /* Contains projects on the town */ leMaireServicess.service('cityService', function($http) { // JSON regions and cities loader this.cities = []; // initCities this.initCities = function() { this.cities = $http.get('data/census/cities.js').success(function(data) { return data; }); return this.cities; }; // Get city info this.getCity = function() { return this.cities; }; }); And in my controller I have // Saved game controller leMaireControllers.controller('GameCoreCtrl', function(

Benefits/drawbacks of additional abstraction layer within Angular's $scope

痞子三分冷 提交于 2019-12-06 12:28:39
I have slightly modified the example from the following URL ( http://docs.angularjs.org/cookbook/helloworld ) as follows, placing the name value within an attrs object property: <!doctype html> <html ng-app> <head> <script src="http://code.angularjs.org/1.2.9/angular.min.js"></script> <script> function HelloCntl($scope) { $scope.attrs = { name : 'World' } } </script> </head> <body> <div ng-controller="HelloCntl"> Your name: <input type="text" ng-model="attrs.name"/> <hr/> Hello {{attrs.name || "World"}}! </div> </body> </html> One benefit I can see is that the HTML source code can be searched

How to load dynamic inline template with angular

狂风中的少年 提交于 2019-12-06 10:21:00
I have an ng-repeat that loops over an array of objects. At each loop the value 'template' & 'values' is initialised. The following version works and uses ng-include to load the template but it happens to be very very slow: <tr class="tableRowsDocs" ng-repeat="dbo in rows track by $index"> <div ng-init="values = dbo.get4(attobj.key); key = attobj.key; template = attobj.template || getAttributeTemplate(dbo.clazz + attobj.key);"> <div class="content" ng-include="template"></div> </div> </td> </tr> The value for template and values is dynamic but it always holds the id of a template/script like:

angular extend $scope is it safe?

点点圈 提交于 2019-12-06 10:11:52
问题 This thread follow angularjs share data config between controllers so I'm wondering if instead of copy by hand property/method is it safe doing like .factory('MyTest',function(){ return { prop: 'Mytest', myFunc: function(){ alert('Hello'); } } }) .controller('IndexCtrl', function ($scope,MyTest) { angular.extend($scope,MyTest); console.log($scope); }) Update It works of course only for property but if it's safe could be a good thing find a way to apply it also for method. UPDATE 1 This seems

AngularJS : How to transclude and have both isolate scope and parent scope?

爷,独闯天下 提交于 2019-12-06 09:38:47
I have a pattern wherein many item types are "editable". This means that I have lots of templates (one for each editable item type) that expect to have unique fields, but common functions (edit, save, cancel edit, delete, etc.). These common functions lead to lots of repetition on controllers: save , edit , cancel , etc., and very repetitive error-handling. One way I looked at of dealing with this was to have each controller "decorate" itself (using a service), but it got messy as well. I prefer a directive, say, 'editable': <form name="editGroup" editable> <div ng-show="editMode"> <!-- lots