angularjs-scope

Binding ngModel to a custom directive

假如想象 提交于 2019-12-21 04:29:08
问题 So I have been working on this issue for a week now and i cannot seem to get my head around this whole Directive thing. I have read lots of posts ... Demystifying Directives Directives Compile, Pre and Post Linking a bunch of videos ... Creating Reusable Directives in AngularJS Writing Directives And gone through StackOverflow and other forums (links to follow) hoping something will sink in ... I think that the problem that I am running into is that I want to UNDERSTAND why/how these work so

angularjs multiple controllers on one page

大憨熊 提交于 2019-12-21 03:20:07
问题 I have a page with multiple controllers, one of the controller is being used in 2 different divs within the same page. I am not sure if it is a scope issue or I just miss something in my code. here is the plunkr http://plnkr.co/edit/IowesXE3ag6xOYfB6KrN?p=preview I want to hide the textbox when the user clicks on 'Savings' link, display the box when clicking on 'Cost' link. 回答1: Every time you use ng-controller, you make a new instance of said controller, with it's own scope. If you set

AngularJS push item to first or 0 index of $scope array

六眼飞鱼酱① 提交于 2019-12-21 03:14:10
问题 Please help me implement this function. I have an array of items in my $scope . Now, when I click on the Add Item button, I want to push a new item to the first index or 0 index of that array. Thanks in advance. :) Here's a working jsFiddle to start with: http://jsfiddle.net/limeric29/7FH2e/ HTML: <div ng-controller="Ctrl"> {{data}}<br/> <input type="button" ng-click="addItem()" value="Add Item" /> </div> JavaScript: function Ctrl($scope) { $scope.data = [ new String('Item 5'), new String(

Directives isolated scope not working properly together with nested views? (AngularJS / UI Router)

喜夏-厌秋 提交于 2019-12-21 02:53:16
问题 I'm using ui-router in a AngularJS project where I have a nested view that contains a custom directive. This directive renders an input field (lets say a filter-field) and its value should be in sync with the controller's scope. This works well for this directive, when the view/state not is nested: jsFiddle / not nested / working as expected var myApp = angular.module('myApp', ['ui.router', 'myComponents']) .config(['$stateProvider', function ($stateProvider) { $stateProvider. state('home', {

AngularJS Multiple Directive Resource Contention

主宰稳场 提交于 2019-12-21 01:59:12
问题 I am trying to build a directive with angular. Here is the plunker I wanted to split it into 3 directives: Top, grand-parent directive. - many DAYS Middle, created with ng-repeat - one DAY Bottom, created with ng-repeat - many TIME BLOCKS angular .directive('dateTimeBlocks', [function dateTimeBlocksDirective () {}]) .directive('dayBlock', [function dayDirective () {}]) .directive('timeBlock', [function timeBlockDirective () {}]) I wanted to create middle and bottom directives with isolated

AngularJS conditional ng-disabled does not re-enable

家住魔仙堡 提交于 2019-12-20 16:10:18
问题 Given a conditionally disabled text input field using ng-disabled="truthy_scope_variable" , AngularJS disables the field the first time the scope variable is falsified, but does not enable it on subsequent changes. As a result, the field remains disabled. I can only assume something went wrong, but the Console log is empty. The truthy scope variable is tied to a radio button model and I can even $watch it change, but the input field's ng-disabled is not working as expected. I have manually

AngularJS : How to pass data from directive to controllers function

大城市里の小女人 提交于 2019-12-20 11:33:28
问题 I'm trying to pass some data from directive into a function addTrackFromPicker in my controller. $scope.addTrackFromPicker = function (message) { console.log("addTrackFromPicker", message); }; Here what I have in my directive dir.directive('youtubeList', function($http, $timeout, YT_event){ return { restrict: 'E', scope: { search: '=', dial: '&' }, templateUrl: 'youtube-list.html', ... Here I want to call controllers function from my template and pass it item.id.$t as argument: <div class=

AngularJS - Format Text Return From JSON To Title Case

自作多情 提交于 2019-12-20 10:19:08
问题 I have a service that retrieves data from a JSON file. Some of the data within the data is all in uppercase, for example: $scope.FootballClubs = [{ CompanyName: [MANCHESTER UNITED, LIVERPOOL FOOTBALL CLUB, CHELSEA, WIGAN UNTIED, LEICESTER CITY] }]; And in my HTML, i am simply throwing about the above: <div ng-repeat="name in FootballClubs"> {{ name.CompanyName }} </div> Which throws out: MANCHESTER UNITED LIVERPOOL FOOTBALL CLUB CHELSEA WIGAN UNTIED LEICESTER CITY What i am trying to display

.config, .run, AppCtrl - where to put routes?

痞子三分冷 提交于 2019-12-20 09:55:23
问题 I wanted to find out the difference between the .config and .run functions in AngularJS. I was using my .config for setting up routes, but I did have some $on 's for watching route change start and success events. I then moved some of this code to .run as I was having some dependency injection problems in .config . I finally moved some of this to a CommonAppController which I have set on my <body> . I also had 2 .config 's and it seemed to be running ok, but surely this isn't right? Can

AngularJS: Select not 2-way binding to model

北慕城南 提交于 2019-12-20 08:55:59
问题 I am using a select to show Client names. A user should be able to select an existing client, which will then update the scope property: Controller Initializing the "first pick". if($scope.clients.length > 0) $scope.existingClient = $scope.clients[0]; View <select id='nm-existing-client-name' class='form-control input-lg' ng-model='existingClient' ng-options="client.name for client in clients"> </select> The scope property existingClient does not change when the select menu changes. If no