angularjs-controller

AngularJS - refresh view after http request, $rootScope.apply returns $digest already in progress

杀马特。学长 韩版系。学妹 提交于 2019-12-22 10:45:37
问题 Hey guys so I am simply trying to load data when my app starts. However, the view loads faster than the http request(of course). I want to refresh my view once my data has been properly loaded because that data defines my view. I've tried $rootScope.apply from inside the factory where I do my http request, and I also tried directly doing the http request in my controller again with $scope.apply, and neither one worked as they both gave me "$digest already in progress" Any idea how can I set

ng-repeat inserting empty anchor tags

梦想的初衷 提交于 2019-12-22 10:15:10
问题 I'm trying to create a menu using angular. A menu item can have children requiring another ng-repeat to print the sub nav items. I'm noticing some strange behavior when attempting to insert an anchor tag within the 2nd ng-repeat. Link to fiddle: http://jsfiddle.net/npU7t/ <li ng-repeat="sub_menu_item in menu_item.sub_menu"> <a href=""> {{ sub_menu_item.title }} </a> </li> With { title: 'menu item with children', sub_menu: [ { title: '<-- empty anchor tag???' } ] } Results in <li ng-repeat=

How to update Directive on State Changes

穿精又带淫゛_ 提交于 2019-12-22 09:44:08
问题 I have a root state that defines the overall structure of the Angular template. In the root state, I have the sidebar included that has dynamic menus via directive that changes based on the state. Like this: .state(‘root', { abstract: true, url: ‘/root', templateUrl: ‘views/root.html', }) root.html includes the sidebar.html that has dynamic menu called through Directive like this: sidebar.html <ul class="nav" id="side-menu"> <li class="nav-header"> <img alt="avatar" ng-src="{{ avatar }}" /> <

AngularJS Drop down values change Dynamically

北城以北 提交于 2019-12-22 09:10:56
问题 I have created two drop downs using AngularJS and appended data in them through the controllers. I want to change the second drop down values when a change occurs in first drop down. I create the example, but when I change value of the first drop down; the second drop down values do not change. 回答1: Updated HTML: <div ng-controller="exerciseTypeCtrl"> <ul data-role="listview" data-inset="true" > <li> <select id="exerciseSuperCategory" data-role="listview" ng-options="catagory as catagory.text

AngularJS: How to share scope functions and variables with other controllers

我怕爱的太早我们不能终老 提交于 2019-12-21 17:51:37
问题 I've multiple controllers in my application, where I have some duplicate code like: $scope.alert = null; $scope.addAlert = function (message) { $scope.alert = { type: 'danger', msg: message }; }; $scope.clearAlerts = function () { $scope.alert = null; }; What is the recommended way sharing these scope functions and variables in AngularJS? Using controller inheritance? 回答1: Create a one controller and then place common methods inside that controller scope. So that you can use that scope

Using $setValidity inside a Controller

末鹿安然 提交于 2019-12-20 08:26:59
问题 I am trying to do some validation on file change. Here is my code: View/Template <input type="file" name="file" id="file" onchange="angular.element(this).scope().setFile(this)" required /> <span class="error" ng-show="myForm.file.$error.required">Error</span> <span class="error" ng-show="myForm.file.$error.size">Selected file is too large</span> <span class="error" ng-show="myForm.file.$error.filetype">Unsupported File type</span> Controller angular.module("myapp").controller("myctrl",

$watch not working on variable from other controller?

余生颓废 提交于 2019-12-19 10:16:56
问题 I have one controller which displays a checklist, and stores the selection in an array. My other controller runs an $http.get on the array from the first controller. How do I set a $watch so that whenever the array changes, a new HTTP GET request is sent? My attempt: http://plnkr.co/edit/EaCbnKrBQdEe4Nhppdfa // See plnkr for other controller + FooSelection factory + view function SimpleQueryResCtrl($scope, $http, FooSelection) { $scope.foo_list_selection = FooSelection; $scope.$watch('foo

AngularJs: Binding ng-model to a list of radio buttons

三世轮回 提交于 2019-12-19 05:23:12
问题 Im trying to bind the selected value in a list of radio buttons to an ng-model I have: <!DOCTYPE html> <html ng-app="testApp"> <head> <script src="./bower_components/angular/angular.min.js"></script> <script src="test.js"></script> </head> <body ng-controller="testController"> <form> <div ng-repeat="option in occurrenceOptions"> <input type="radio" name="occurrence" ng-value="option" ng-model="selectedOccurrence" /><label>{{ option }}</label> </div> </form> <div>The selected value is : {{

AngularJS : How to create a two-way data binding between two isolated controllers and a shared service?

坚强是说给别人听的谎言 提交于 2019-12-18 13:00:49
问题 I am trying to create a two-way data binding between two isolated controllers and a shared service (which provides another isolated scope): app.factory("sharedScope", function($rootScope) { var scope = $rootScope.$new(true); scope.data = "init text from factory"; return scope; }); app.controller("first", function($scope, sharedScope) { $scope.data1 = sharedScope.data; }); app.controller("second", function($scope, sharedScope) { $scope.data2 = sharedScope.data; }); Fiddle: http://jsfiddle.net

AngularJS: Should I convert directive's linking function to a controller?

送分小仙女□ 提交于 2019-12-18 11:15:16
问题 I heard it's a good practice to use the controllerAs syntax along with bindToController: true in directives that use an isolate scope. References: one, two Suppose, I have a directive like this: angular.module('MyModule').directive('MyDirective', function(User) { return { scope: { name: '=' }, templateUrl: 'my-template.html', link: function(scope) { scope.User = User; scope.doSomething = function() { // Do something cool }; } }; }); <!-- my-template.html --> <div> User Id: {{ User.id }} Name: