Created
March 2, 2017 13:08
-
-
Save aledwassell/b42993ff22d349fee33a91df393842ac to your computer and use it in GitHub Desktop.
angular directives, using angular directives to manipulate the dom and change also using them as form validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myApp = angular.module('myApp', []); | |
myApp.controller('mainController', ['$scope', '$filter', function($scope, $filter) { | |
$scope.handle = ""; | |
$scope.lowerCaseFilter = function() { | |
return $filter('lowercase')($scope.handle); | |
}; | |
$scope.characters = 5; | |
$scope.rules = [ | |
{ rulename: "Must be more than 5 characters."}, | |
{ rulename: "Must not be used elsewhere."}, | |
{ rulename: "Must be rad yeah"} | |
]; | |
}]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div ng-controller="mainController"> | |
<label>What is your twitter handle</label> | |
<input type="text" ng-model="handle"/> | |
<div class="alert" ng-class="{'alert-warning': handle.length < characters}" ng-show="handle.length !== characters"> | |
<div ng-show="handle.length < characters"> | |
you got less than 5 characters | |
</div> | |
</div> | |
<hr/> | |
<h1>twitter.com/{{lowerCaseFilter()}}</h1> | |
<h3>Rules</h3> | |
<ul> | |
<li ng-repeat="rule in rules"> | |
{{ rule.rulename }} | |
</li> | |
</ul> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment