angularjs-model

Why is Angularjs ng-pattern not working with the following regexp?

删除回忆录丶 提交于 2020-01-20 03:52:38
问题 For some reason the initialized value doesn't appear in the field, but the second field without the ng-pattern does work. any ideas? angular.module('app', []).controller('MainCtrl', function($scope) { $scope.widget = {title: 'abc', title2: 'abc'}; }); <div ng-app="app" ng-controller="MainCtrl"> <input ng-model="widget.title" required ng-pattern="/[a-zA-Z]{4}[0-9]{6,6}[a-zA-Z0-9]{3}/"> <br /><br /> input 1: {{ widget.title }} <br /><br /> <input ng-model="widget.title2" required> <br /><br />

AngularJS - how to change the value of ngModel in custom directive?

巧了我就是萌 提交于 2019-12-18 10:13:38
问题 Lets take a look to my directive: angular.module('main').directive('datepicker', [ function() { return { require: '?ngModel', link: function(scope, element, attributes, ngModel) { ngModel.$modelValue = 'abc'; // this does not work // how do I change the value of the model? So, how do I change the value of the ng-model? 回答1: There are different ways of doing it: $setViewValue() updates the view and the model. Most cases it is enough. If you want to disconnect view from the model (e.g. model is

Referencing the element that is calling a controller function Angularjs ( ng-change / ng-blur / ng-* ? )

限于喜欢 提交于 2019-12-14 03:02:43
问题 The original question asked about how to determine which element called the controllers blurr function, but I didn't clarify that I was not specifically asking about ng-blur , but ng-* ( ng-change , ng-focus , ng-mouseover , ng-*) in general. So, with that in mind: How do I determine which element input is calling the blurr() and/or check() functions? html <body ng-app="test"> <div ng-controller="Cntrlr as cntrlr"> <form name="meta_test"> <input type="text" name='inpt' ng-model="cntrlr.inpt"

angularJS element.on callback and scope.$apply

你离开我真会死。 提交于 2019-12-07 03:44:55
问题 In this example, I have an input with an attached directive. The directive is meant to display messages next to the input. There's another input and a button to add messages. Once some messages are displayed, focusing on the input with the attached directive should clear the messages. http://jsfiddle.net/viro/WBqxf/ So I have a directive with an isolated model, and I'm trying to update the model when the element which has the directive goes into focus. It seems like I have to wrap event

Referencing the element that's calling a controller function Angularjs

蓝咒 提交于 2019-12-06 15:59:08
问题 Fairly simple but I can't figure out the term I need to google. How do I reference whichever element is calling the controllers blurr function? html <body ng-app="test"> <div ng-controller="Cntrlr as cntrlr"> <input type="text" ng-model="cntrlr.inpt" ng-blur="cntrlr.blurr()" /> <input type="text" ng-model="cntrlr.second" ng-blur="cntrlr.blurr()" /> </div> </body> js var app = angular.module("test", []); app.controller("Cntrlr", ["$scope", function($scope){ this.blurr = function(){ alert(

Referencing the element that's calling a controller function Angularjs

淺唱寂寞╮ 提交于 2019-12-04 22:43:31
Fairly simple but I can't figure out the term I need to google. How do I reference whichever element is calling the controllers blurr function? html <body ng-app="test"> <div ng-controller="Cntrlr as cntrlr"> <input type="text" ng-model="cntrlr.inpt" ng-blur="cntrlr.blurr()" /> <input type="text" ng-model="cntrlr.second" ng-blur="cntrlr.blurr()" /> </div> </body> js var app = angular.module("test", []); app.controller("Cntrlr", ["$scope", function($scope){ this.blurr = function(){ alert("which input am I?"); alert("this is so meta."); // ? }; }]); [edit] I realized I meant to be more abstract

AngularJS - how to change the value of ngModel in custom directive?

柔情痞子 提交于 2019-11-29 20:16:50
Lets take a look to my directive: angular.module('main').directive('datepicker', [ function() { return { require: '?ngModel', link: function(scope, element, attributes, ngModel) { ngModel.$modelValue = 'abc'; // this does not work // how do I change the value of the model? So, how do I change the value of the ng-model? There are different ways of doing it: $setViewValue() updates the view and the model. Most cases it is enough. If you want to disconnect view from the model (e.g. model is a number but view is a string with thousands separators) then you could access directly to $viewValue and

Why is Angularjs ng-pattern not working with the following regexp?

我们两清 提交于 2019-11-29 03:19:30
For some reason the initialized value doesn't appear in the field, but the second field without the ng-pattern does work. any ideas? angular.module('app', []).controller('MainCtrl', function($scope) { $scope.widget = {title: 'abc', title2: 'abc'}; }); <div ng-app="app" ng-controller="MainCtrl"> <input ng-model="widget.title" required ng-pattern="/[a-zA-Z]{4}[0-9]{6,6}[a-zA-Z0-9]{3}/"> <br /><br /> input 1: {{ widget.title }} <br /><br /> <input ng-model="widget.title2" required> <br /><br /> input 2: {{ widget.title2 }} </div> Here is the Fiddle http://jsfiddle.net/wkzab/1/ UPDATE I looked