Skip to content

Instantly share code, notes, and snippets.

@syads321
Last active April 1, 2017 06:43
Show Gist options
  • Save syads321/2a0d3b05967dd48a0f411056991aeab8 to your computer and use it in GitHub Desktop.
Save syads321/2a0d3b05967dd48a0f411056991aeab8 to your computer and use it in GitHub Desktop.
//https://codepen.io/anon/pen/gmeewN
//https://codepen.io/anon/pen/RpyVag
//https://codepen.io/anon/pen/QprqKZ
//https://codepen.io/anon/pen/MpPOMg
//https://codepen.io/anon/pen/VpEqOE
//https://codepen.io/anon/pen/MpzOEP
//https://www.webpackbin.com/bins/-Kgc4ylGu6eVLHnUQbyA
$scope.elements = [
{ type: 'text', id: 'DJDK-343434', label: 'edit label', value: 'holle' }
]
phonecatServices.factory('elmHtml', function() {
return {
text: '<input type="text" ng-model="defaultvalue">',
paragraph: '<textarea ng-model="defaultvalue"></textarea>'
};
});
phonecatDirectives.directive('formElm', function($compile, elmHtml) {
return {
'restrict': 'E',
// 'require': '?ngModel',
'scope': {
"ngModel": "=" // two way binding
},
'controller': function($scope, $element) {
$scope.hello = function() {
alert('hello');
}
$scope.defaultvalue = $scope.ngModel.value;
$scope.$watch('defaultvalue', function(value) {
$scope.ngModel.value = value;
})
},
'link': function(scope, element, attrs, ngModel) {
console.log(elmHtml);
// element.html('<input type="text" ng-model="defaultvalue">');
// $compile(element.contents())(scope);
scope.$watch('ngModel.type', function(value) {
element.html(elmHtml[value]);
$compile(element.contents())(scope);
})
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment