angularjs-scope

How to set a default value in an AngularJS Directive Scope?

天涯浪子 提交于 2019-12-10 13:27:53
问题 In AngularJS, I have the following scenario where a directive can accept an optional boolean parameter which should default to true by default, whenever it is not specified . Example: <my-directive data-allow-something="false"> ... this works as expected as no default value should be set in this case ... </my-directive> <my-directive> ... but in this case i'd like allowSomething to equal true ... </my-directive> I've tried the following approach, but for some reason the true value doesn't

Trap focus in html container with angular

橙三吉。 提交于 2019-12-10 13:04:45
问题 I'm building an accessible website and trying to manage focus. I need to open a modal and then put focus on the first element in the modal then trap the focus until the modal is closed ("canceled" or "accepted"). HTML <a href="" ng-click="modalshow = !modalshow; modal.open();">Open Modal</a> <div ng-show="modalshow" id="modal"> <h3 id="tofs" >Terms of Service</h3> <p>Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum </p> <span>Cancel</span> <span>Accept/span> </div> <h2>Seprate Content</h2>

“Cannot read property 'id' of undefined” when parsing an array declared in a factory

a 夏天 提交于 2019-12-10 12:59:15
问题 I am building a basic app (with MEAN web frameworks and node webkit) in order to understand angularjs better. Here is the content of my notificationFactory.js function notificationFactory() { var fooMessages = [ { id: 4, dismissable: true, name: "fooooBaaar", function: '', showInTopBar: false, priority: "high", icon: 'fooIconBarBarBar', topBarIcon: 'fooIconIconIcon' }, { id: 3, dismissable: true, name: "foofooBarBar", function: '', showInTopBar: false, priority: "high", icon: 'fooIconfooIcon'

Manually trigger Angular data binding for an input field (for unit testing purposes only)

Deadly 提交于 2019-12-10 12:46:43
问题 I'm writing some tests for an Angular directive and I need to simulate user input into an input field. I tried to do this: element.find('input').val('some value').trigger('input'); but it didn't work. Triggering change didn't work either. I know I can access the element scope directly with element.scope() and change it, but it seems more natural to change the input's value and let Angular do the data binding. For what it's worth, I've checked out input(name).enter(value) from Angular

Angular directive: using ng-model within isolate scope

流过昼夜 提交于 2019-12-10 12:38:06
问题 I'm having trouble working out how I can define a custom directive that both: Uses isolate scope, and Uses the ng-model directive in a new scope within in its template. Here's an example: HTML: <body ng-app="app"> <div ng-controller="ctrl"> <dir model="foo.bar"></dir> Outside directive: {{foo.bar}} </div> </body> JS: var app = angular.module('app',[]) .controller('ctrl', function($scope){ $scope.foo = { bar: 'baz' }; }) .directive('dir', function(){ return { restrict: 'E', scope: { model: '='

If else conditions in angularjs templates

不问归期 提交于 2019-12-10 12:34:10
问题 I am quite new to AngularJs. I am working on a Q&A Application where i have to render some questions and its answers in the form of a table. I have three Types of questions which I have to render in a different way. Every question has a type assigned with it. If question.type is "MCQ" then the options or its answer should be rendered with HTML checkbox, and if question type is NUM its answers should be rendered with radio buttons. i tried this and use if conditions in AngularJs Template. my

How to set first controller data another controller

谁说我不能喝 提交于 2019-12-10 11:55:09
问题 Here I added categoryCtrl and ProductCtrl. This code line console.log(category); is working properly. How to bind this data for the product controller using for loop or whatever. .controller('CategoryCtrl', function($scope, $http) { var vm = this; vm.playlists = {}; $http.get("http://localhost/youtubewebservice/shop-categorylist-product.php").then(function(response) { vm.playlists = response.data.category; console.log(response.data.category); }); $scope.selectedJsonObject=function(category){

md-tabs: setting variable for md-selected not working when calling function from inside ui-router

本秂侑毒 提交于 2019-12-10 11:50:05
问题 I have a ui-router template containing md-tabs from which some tabs are static, others are created dynamically using ng-repeat iterating through a given array of the data model. Inside those dynamically created tabs there are three buttons to do the following move tab left by one position move tab right by one position The move tab buttons call a function inside the same controller. The $index value of the currently shown tabs as well as the desired direction ( -1 for moving left, 1 for

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

喜欢而已 提交于 2019-12-10 11:37:40
问题 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"

How to get controller scope from multi-level directives in AngularJS(without $parent)

僤鯓⒐⒋嵵緔 提交于 2019-12-10 11:16:32
问题 How can I access controller scope from multi-level directives in below structure: I create a directive that has multi-level scopes inside its. 1. Controller scope 1.2. Directive1 scope(main directive) 1.2.1. Directive2 scope 1.2.1.1 Directive3 scope I want to get the controller scope from directive 3. please don't refer to $parent because the parent level it's not certain and a user may use this directive inside another directive.(see below codes) <div ng-controller="Test"> <custom-dir> <dir1