angularjs-directive

Isolate Scope “=” binding and doted notation AngularJS

柔情痞子 提交于 2019-12-12 08:09:43
问题 How do you create a 2 way binding with a nested property in an isolate scope with dotted notation. I thought 'myObject.data': "=data" would work, but it does not. I don't want to link everything in the myObject object. I know I could do some sort of watch, but 'myObject.data' seems cleaner. .directive("myDirective", [function() { return { restrict: "E", scope: { 'myObject.data': "=data" }, link: function (scope, element, attrs) { scope.myObject = { data: "myValue" }; } }; }]) 回答1: Isolated

AngularJS: How to stop event propagation from ng-click?

拥有回忆 提交于 2019-12-12 07:53:48
问题 I have directive that does something like so: app.directive('custom', function(){ return { restrict:'A', link: function(scope, element){ element.bind('click', function(){ alert('want to prevent this'); }); } } }); yes, it's necessary to do jQuery-way binding for this case. And now I want to stop this event(click) propagation if some condition met. Tried to do: $event.stopPropagation(); $event.preventDefault(); but it did not help. here fiddle for example - http://jsfiddle.net/STEVER/5bfkbh7u/

AngularJS : Decision tree implementation

纵饮孤独 提交于 2019-12-12 07:03:31
问题 I am trying to write a quiz app.Below is the source code.Currently it is working like as below : On Click start Quiz,first questions shows up. User selects correct option and it moves to say question number 3. if User selects wrong option,it moves to another question say question number 4. and so on... Please check link http://plnkr.co/edit/sYG9jjX0JATbQhJ1hNf6 What I want to achieve is as below : On Click start Quiz,first questions shows up. User selects correct option and it moves to say

AngularJs update directive after a call to service method

不打扰是莪最后的温柔 提交于 2019-12-12 06:36:06
问题 I'm trying to create resusable alert service, which I would call anywhere in my application with just: alertService.showAlert('warning', 'something went wrong!'); For example after ajax call to backend api. Right now I'm using a factory and a directive, but It seems I'm doing something wrong, because the directive does not update after a call to showAlert method. Right now I have something like this: var srv = angular.module('srv', []); srv. factory('alertService', ['$timeout', function(

Directive working in one controller and not in another

吃可爱长大的小学妹 提交于 2019-12-12 05:48:20
问题 I am trying to follow the foodMe example on AngularJS. I am on step 21. Instead of creating a ng-model, I tried to do it a bit different, created a Plunker here. My issue is it only works in Restaurants.html and not inside Menu.html. I can even see the value of {{restaurant.rating}} when I view the source , e.g. <span stars rating="{{restaurant.rating}}" readonly="true"></span> In the HTML view-source I can see rating="3". Only a small change from my plunker vs my sandbox is in my sandbox I

Error: rootScope:infdig 10 $digest() iterations reached. Aborting

一曲冷凌霜 提交于 2019-12-12 05:38:35
问题 I have created a custom directive that takes some scope parameters. I used a watchGroup for incoming parameters change. This is part of the directive: scope.$watchGroup(['repairer', 'initial'], function() { if (scope.initial) { scope.Repairer = scope.initial; } else { scope.Repairer = scope.repairer; } console.log('scope.Repairer value:', scope.Repairer); if (scope.Repairer) { console.log('wooohoo calling scriptservice'); scriptingService.getScript(scope.request).then(function(scripts) {

Directive scope variable not working with ng-show

拟墨画扇 提交于 2019-12-12 05:27:44
问题 I have a "home" controller that uses a directive. I want to be able to show/hide a button in the directive template depending on the value of a variable in the controller. This is what my directive looks like: angular.module("goleadoresApp").directive("golNavbar", [golNavbar]); function golNavbar() { return { restrict: "EA", templateUrl: "views/templates/golNavbar.html", scope: { pageTitle: "@", showLockIcon: "@" } }; } And my template: <div class="bar bar-header bar-balanced"> <h1 class=

AngularJS - passing variable to scope (from directive to use it in controller) not working

ぐ巨炮叔叔 提交于 2019-12-12 05:26:52
问题 I would ask for some help and explanation on the given issue. It seems like I can not pass variable to scope from directive to use it in controller, variable is called caret_position . Please see below code. Controller var myApp = angular.module('myApp', []); myApp.controller('Composer', function Composer($scope, $http) { // getting snippets json data $http.get('data/snippets/default.json').success(function(data) { $scope.snippets = data; $scope.snippets.count = data.length; }); // adding

how to execute the statement after promise is executed?

我的梦境 提交于 2019-12-12 05:26:08
问题 I have used the following directory in my template i want to change the model value of drop-down to id for it i have used as bellow <md-select flex class="md-select-form" ng-model="education.degree" placeholder="Degree" save-id id="education.degree_id" "> <md-option ng-value="degree" ng-repeat="degree in ['High School', 'Associates Degree', 'Bachelor Degree', 'Masters Degree', 'M.B.A', 'M.D', 'Ph.D', 'other']">{{degree}}</md-option> </md-select> .directory code .directive('saveId', function

Testing directive in Angular 2 + Jasmine I am getting an error

梦想的初衷 提交于 2019-12-12 05:19:11
问题 I am getting the error below when I run the test using Angular 2 + Jasmine. Does anyone know how can I solve this problem? I already have imported the directive in app.module.ts. Can't bind to 'highlightData' since it isn't a known property of 'li'. ("[ERROR ->][highlightData]="item.name"> list.component.ts <ul> <li *ngFor="let item of list" [highlightData]="item.name">{{item.name}}</li> </ul> highlight-data.directive.ts import { Directive, SimpleChanges, Input, OnChanges, ElementRef,