Created
February 7, 2014 13:19
-
-
Save kibernick/8862508 to your computer and use it in GitHub Desktop.
Angular.js directive for manipulating data in the form of an array of strings (e.g. address lines, etc.)
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
myApp.directive("testing", [function() { | |
return { | |
restrict: "E", | |
templateUrl: "testing.html", | |
link: function(scope, element, attrs) { | |
scope.logIt = function() { | |
console.log(scope.someobj); | |
}; | |
scope.addLine = function() { | |
scope.someobj.push(""); | |
//if (scope.$root.$$phase != '$apply' && scope.$root.$$phase != '$digest') { scope.$apply(); }; | |
}; | |
scope.takeItOut = function(position) { | |
//if (scope.$root.$$phase != '$apply' && scope.$root.$$phase != '$digest') { scope.$apply(); }; | |
console.log(scope.someobj) | |
console.log("taking out: " + position); | |
var tookOut = scope.someobj.splice(position, 1); | |
console.log(scope.someobj) | |
console.log("took out: " + tookOut); | |
}; | |
}, | |
scope: { | |
someobj: "=" | |
} | |
} | |
}]) |
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
<ol> | |
<li ng-repeat='part in someobj track by $index'> | |
<input ng-model="someobj[$index]"> | |
<button type="button" class="btn btn-danger btn-xs" ng-click="takeItOut($index)">x</button> | |
</li> | |
</ol> | |
<button type="button" ng-click="logIt()" class="btn btn-default">logIt</button> | |
<button type="button" ng-click="addLine()" class="btn btn-default">addLine</button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment