angularjs-directive

Call a method of a controller from another controller using 'scope' in AngularJS

a 夏天 提交于 2019-12-17 07:12:33
问题 I am trying to call a method of second controller in first controller by using scope variable. This is a method in my first controller: $scope.initRestId = function(){ var catapp = document.getElementById('SecondApp'); var catscope = angular.element(catapp).scope(); catscope.rest_id = $scope.user.username; catscope.getMainCategories(); }; I am able to set the value of rest_id but I cannot call getMainCategories for some reason. The console shows this error: TypeError: Object # has no method

How to use “ng-repeat” within template of a directive in Angular JS?

谁说我不能喝 提交于 2019-12-17 07:10:29
问题 I'm new to Angular JS and I am trying to create a custom directive that will be used as below: <div linkedlist listcolumns="{{cashAccountsColumns}}"></div> Corrps. controller will be: $scope.cashAccountsColumns = [ {"field": "description", "title": "Description"}, {"field": "owner", "title":"Owner"}, {"field": "currentBalance", "title":"Current Balance" } ]; And the directive code is: return { restrict : 'EA', transclude : false, templateUrl : 'html/linkedlist.html', scope: { listcolumns: "@"

Detect unsaved changes and alert user using angularjs

荒凉一梦 提交于 2019-12-17 07:05:33
问题 Below is the code so far <!doctype html> <html ng-app> <head> <script src="http://code.angularjs.org/1.1.2/angular.min.js"></script> <script type="text/javascript"> function Ctrl($scope) { var initial = {text: 'initial value'}; $scope.myModel = angular.copy(initial); $scope.revert = function() { $scope.myModel = angular.copy(initial); $scope.myForm.$setPristine(); } } </script> </head> <body> <form name="myForm" ng-controller="Ctrl"> myModel.text: <input name="input" ng-model="myModel.text">

Binding variables from Service/Factory to Controllers

折月煮酒 提交于 2019-12-17 07:04:27
问题 I have a variable that will be used by one or more Controllers, changed by Services. In that case, I've built a service that keeps this variable in memory, and share between the controllers. The problem is: Every time that the variable changes, the variables in the controllers aren't updated in real time. I create this Fiddle to help. http://jsfiddle.net/ncyVK/ --- Note that the {{countService}} or {{countFactory}} is never updated when I increment the value of count. How can I bind the

Dynamic form name attribute <input type=“text” name=“{{ variable-name }}” /> in Angularjs

流过昼夜 提交于 2019-12-17 06:47:11
问题 How would someone use formName.inputName.$valid when the "inputName" was dynamically created? <form name="formName"> <input ng-repeat="(variable) in variables" type="text" name="variable.name" ng-model="variable.name" required /> </form> The output of the HTML input attribute 'name' would be the string "variablename", which would applied to ALL repeated inputs. If we tried this <form name="formName"> <input ng-repeat="(variable) in variables" type="text" name="{{ variable.name }}" ng-model=

AngularJS - how to override directive ngClick

烈酒焚心 提交于 2019-12-17 06:39:14
问题 I want to override directive ng-click: to some make some $rootscope changes before each execution of ng-click. How to do it? 回答1: You can't override AngularJS built-in directives. However, you can define multiple directives with the same name and have them executed against the same element. By assigning appropriate priority to your directive, you can then control whether your directive runs before or after a built-in directive. This plunker shows how to build an ng-click directive that

AngularJS Group By Directive without External Dependencies

泪湿孤枕 提交于 2019-12-17 06:29:50
问题 I'm new to Angular and would like to learn the best way to handle a problem. My goal is to have a reusable means to create group by headers. I created a solution which works, but I think this should be a directive instead of a scope function within my controller, but I'm not sure how to accomplish this, or if a directive is even the right way to go. Any inputs would be greatly appreciated. See my current approach working on jsFiddle In the HTML it's a simple list using ng-repeat where I call

How to validate email id in angularJs using ng-pattern

↘锁芯ラ 提交于 2019-12-17 06:27:18
问题 Am trying to validate an Email id field in angularJs using ng-pattern directive. But am new to AngularJs. I need to show an error message as soon as the user enters the wrong email id. The code which I have below is am trying to solve. Help me out with using ng-pattern for getting the proper result. <script type="text/javascript" src="/Login/script/ang.js"></script> <script type="text/javascript"> function Ctrl($scope) { $scope.text = 'enter email'; $scope.word = /^[a-z]+[a-z0-9._]+@[a-z]+\.

Custom form validation directive to compare two fields

这一生的挚爱 提交于 2019-12-17 06:05:10
问题 I'm an angular newbie, and I'm stumbling over something in how angular's form validation directives work. I know that I can fairly easily add directives to individual fields , but I'm trying to add a validation which will compare two form fields (both of which are elements of a model). Here's a form skeleton: <form name="edit_form" > <input name="min" type="number" ng-model="field.min"/> <input name="max" type="number" ng-model="field.max"/> </form> <div class="error" ng-show="edit_form.min.

if a ngSrc path resolves to a 404, is there a way to fallback to a default?

江枫思渺然 提交于 2019-12-17 03:24:07
问题 The application I'm building requires my user to set 4 pieces of information before this image even has a chance of loading. This image is the center-piece of the application, so the broken image link makes it look like the whole thing is borked. I'd like to have another image take its place on a 404. Any ideas? I'd like to avoid writing a custom directive for this. I was surprised that I couldn't find a similar question, especially when the first question in the docs is the same one! http:/