angularjs-scope

Angularjs - ng-model undefined

陌路散爱 提交于 2019-12-12 19:27:07
问题 I am building a rather complex directive in which I need access to ng-model on a specific element in the template which is enclosed into ng-if directive... I have a plunker and the explanation on how to see the issue is below. In the .compile function of the directive I have a line of code that looks like this ngModel = elm.find('textarea').controller('ngModel'); console.log(ngModel); In my template, I have a something like this: <div ng-if="views.view"> <textarea ng-model="exp.val"><

Adding a new element into the DOM with angularjs does not initiate it

安稳与你 提交于 2019-12-12 18:22:13
问题 Explaining further, I am using angular-summernote and I am using a directive to insert new WYSIWYG editor instances inside of the DOM. However, when I insert it into the DOM, the new editor does not load maybe because the init has already been fired. Here is the directive I am using, as well as a jsFiddle that works, it does insert the editor tags but it does not generate/start another editor: JSFiddle angular.module('summernoteDemo', ['summernote']) .directive('addSummernote', function () {

How do I update an angularjs page after a scope update?

为君一笑 提交于 2019-12-12 16:23:24
问题 I have written a directive that captures keyboard events, and on certain keys I update some objects in the scope. The idea is to move up and down an array and display the selected row details. The problem is the page is not updated until I do another action that updates the page. How can I force this? Here's the directive: LogApp.directive("keyCapture", [function(){ var scopeInit; return{ link: function(scope, element, attrs, controller){ scopeInit = scope element.on('keydown', function(e){

Binding doesn't update when the original object changes

无人久伴 提交于 2019-12-12 14:54:38
问题 I think I have misunderstood something about how data-binding and scopes work in Angular, or maybe I have some misconception in Javascript in general. I hope somebody can help me. Let's say I have a factory that has an object, and defines a getter/setter for it: app.factory('myFactory', function(){ var myObject : { subObject : { subProperty : 'value' } }; return { getObject : function() { return myObject; }, setObject : function(obj) { myObject = obj; } }; }; Then, in a controller I get this

Broadcast not received in directive

瘦欲@ 提交于 2019-12-12 13:35:05
问题 I have a parent-child controller relationship between my <main> , <div> and <my-directive> as such: <main ng-controller="MainController"> <nav> <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> </ul> </nav> <div ng-controller="AboutController"> </div> <my-directive></my-directive> </main> Within the MainController, i perform a $broadcast with a: $scope.$broadcast('shoppingCartReady', msg); Within AboutController, i can successfully receieve this $broadcast via: angular.module('aboutModule', []

Angular view (DOM elements) not being updated when model changes

半城伤御伤魂 提交于 2019-12-12 13:26:59
问题 Running latest stable version of Angular in latest stable Chrome. I have an ng-click on a DOM element that's inside a view with ng controller A, but the DOM element itself has an ng-controller set to another controller, B. ng-click fires inside controller B, however changes to scope properties, which DOM element is bound to by its ng-model attribute, are not reflected. Specifically I have a textarea, as well as other HTML5 input types. No errors, and when I break in the debugger, I can look

Dynamic dropdown select in AngularJS not working

半腔热情 提交于 2019-12-12 12:27:29
问题 I am practicing with Angular and want to give users the option to choose from 3 dropdown select menus. The third menu should be dynamic depending on the selection from the previous two menus. My html: // First dropdown menu, static <select ng-model="selectedLetter" ng-change="setColorSelection()" ng-options="letter as letter for letter in letters"> </select> <br> // second dropdown menu, static <select ng-model="selectedNumber" ng-change="setColorSelection()" ng-options="number as number for

angular.js directive templateUrl fails to bind scope

对着背影说爱祢 提交于 2019-12-12 11:20:16
问题 I'm creating a directive that will display and show content by listening to the $routeChangeError event on $rootScope. I got it all to work by inlining the template like this: app.directive("alert", function ($rootScope) { 'use strict'; return { restrict: "E", replace: true, template: '<div class="alert alert-warning alert-dismissable" ng-show="isError">' + '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>' + '{{ message }}' + '</div>', //templateUrl:

AngularJS - access directive scope from transclude scope

孤街醉人 提交于 2019-12-12 11:17:39
问题 I have a directive with some form. Usually it is all I need, but sometimes I need to add some more input fields. So I tried to use transclusion for that, but it doesn't work. I created a plunker to ilustrate that: http://plnkr.co/edit/zNOK3SJFXE1PxsvUvPBQ?p=preview Directive is a simple form with input field, transclusion and a button to help testing it (not important parts ommitted): scope: { }, transclude: 'element', template: '<form name="myForm">' + '<input type="text" ng-model="data

Calling Javascript within ng-if

丶灬走出姿态 提交于 2019-12-12 10:45:32
问题 I have some legacy jQuery code. It's a big chunk of code, so I would prefer to port it a little while later. To use it, I call $('#legacyId').legacyFunction() . Here's the deal, though. I have an ng-if. And within that ng-if, I have the JavaScript where I call my legacy function. <div ng-if="status=='yes'"> <div id="legacyId"> I am a legacy div! </div> <script type="text/javascript"> $('#legacyId').legacyFunction() </script> </div> It looks like this JavaScript is being called when the page