javascript - can you use an expression inside of NG-MODEL? -
i want use expression inside of ng-model directive there way accomplish binding? can done using compile? here markup
<!doctype html> <html> <head> <title></title> <link href="content/bootstrap.min.css" rel="stylesheet" /> </head> <body ng-controller="appctrl"> <div></div> <range min="0" max="100" model="width"></range> </body> </html> <script src="scripts/angular.min.js"></script> <script> var app = angular.module("pager", []); app.run(function($rootscope){ console.log($rootscope); }); angular.element(document).ready(function(){ angular.bootstrap(document.queryselector("html"), ["pager"]); }) app.directive("range", function ($compile) { return { restrict: "e", replace: true, scope:{ min:"@", max:"@", model:"@" }, template: "<input type='range' ng-model='{{model}}' value='0' min='{{min}}' max='{{max}}'/>", } }) </script>
ng-model='{{model}}' gives error there way read model attribute directive? possible link way or have use $compile accomplish this. want directives able create variables in child scope bind ng-model directive generating. want use attribute of "model" directive create variable ng-model. in example want "width" {{model}} expression is.
is looking for?
if replace @
=
see on controller $scope
(without using expression), take @ below code , fiddle.
edit
app.directive("range", function ($compile) { return { restrict: "e", replace: true, scope: { min: "@", max: "@", model: '=' }, compile: function () { return { pre: function (scope, elem, attrs) { // directives isolated scope console.log(scope); // controller scope console.log(scope.$parent); } } }, template: "<input type='range' ng-model='model' value='0' min='{{min}}' max='{{max}}'/>" } });
Comments
Post a Comment