Last active
December 19, 2016 15:01
-
-
Save heidsoft/3e1843e20d57d0f75314ee3cf16ee737 to your computer and use it in GitHub Desktop.
angularjs $compile 使用
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
| $("#dynamicContent").html( | |
| $compile( | |
| "<button ng-click='count = count + 1' ng-init='count=0'>Increment</button><span>count: {{count}} </span>" | |
| )(scope) | |
| ); |
Author
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.checkUsername = function() {
//send ajax to check on server
if ($scope.username === 'hellobug') {
$scope.usernameAlreadyExist = true;
}
};
});
app.directive('ngBlur', function($document) {
return {
link: function(scope, element, attrs) {
$(element).bind('blur', function(e){
scope.$apply(attrs.ngBlur);
});
}
};
});
app.directive('repeater', function($document) {
return {
restrict: 'A',
compile: function(element, attrs) {
var template = $(element).children().clone();
for(var i=0; i<attrs.repeater - 1; i++) {
$(element).append(template.clone());
}
}
};
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.