AngularJS add ng-model at compile time -
AngularJS add ng-model at compile time -
i have created directive called click-to-edit
you utilize like
<click-to-edit="somevalue">
where $scope.somevalue=7;
i have since realized need utilize ngmodel controller, , easier if recompile directive , add together ng-model="somevalue"
template. im having problem doing giving me error
"error: [$compile:ctreq] controller 'ngmodel', required directive 'clicktoedit', can't found!"
this because have
require:'ngmodel'
this snippet of code far
return { restrict: 'a', replace: true, require: 'ngmodel', priority: 100, compile: function(telement, tattrs, transclude) { // right ngmodel isolate scope tattrs.$set('ngmodel', tattrs.clicktoedit, false); } homecoming { post: linkfn }; }, scope: { dp: '=?', type: '@', fn: '=?', //<--- formula editfn:'&?' // if want execute function on valid save, add together }
what want do, take directive looks like
<click-to-edit="model"/>
, alter to
<click-to-edit="model" ng-model="model"/>
and have compile , work expected.
let me know if need other code.
i'm not sure if you've considered - why not do:
<click-to-edit ng-model="model"/>
to reply original question, suggest adding body directive:
.directive('body', function() { homecoming { restrict: 'e', compile: function(element, attr) { $('[click-to-edit]', element).attr('ng-model', 'model'); } } })
plunker here
angularjs
Comments
Post a Comment