Skip to content

Instantly share code, notes, and snippets.

@mklickman
Created March 19, 2018 15:17
Show Gist options
  • Save mklickman/08ae7ca40cc53d90937482c3f3386840 to your computer and use it in GitHub Desktop.
Save mklickman/08ae7ca40cc53d90937482c3f3386840 to your computer and use it in GitHub Desktop.
<form class="zip-input-group" zip-input ng-submit="checkZip()">
<input class="zip-input-text" name="zip-text" type="text" maxlength="5" required>
<input type="submit" value="Go!" class="zip-input-submit">
</form>
angular.module('myApp')
.directive('zipInput', function() {
return {
restrict: "A",
scope: {},
controller: [$scope, function zipInputController($scope) {
$scope.checkZip = function() {
console.log("ZIP form submitted!");
}
}]
}
});
@babilog
Copy link

babilog commented Mar 19, 2018

Have you tried using the link prop instead of controller?

    .directive('zipInput', function() {

        return {
            restrict: "A",
            link: function ($scope, element, attrs) {
                $scope.checkZip = function() {
                    console.log("ZIP form submitted!");
                }
        }
});

@mklickman
Copy link
Author

I haven't tried it, and that may work, but I'm not a huge fan of putting all my logic inside the link function, when the controller is specifically designed to handle all that. I'm more interested in why it's not working. Thanks for the suggestion though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment