angularjs - Getting controller model from isolate scope directive -


i know there billion questions isolate scope on here, not find 1 directly relates exact issue.

i have property on controller called model, .. $scope.model. have directive needs interact model.

i wanting give directive isolate scope, proving bit difficult because doing means no longer have access model. thought solve specifying model two-way binding in isolate scope, this.

html

<body ng-app="app" ng-controller="homecontroller">    <div custom-directive="model.tags"></div> </body> 

javascript

app.directive('customdirective', ['$parse', function($parse) {    return {       restrict: "a",       scope: {          customdirective: "=model"       },       link: function(scope, element, attributes){          // need access controller's "$scope.model" here things.          var model = scope.$eval(attributes.customdirective);       }    } }]) .controller('homecontroller', ['$scope', function($scope) {    $scope.model = {       id: "items/1",       name: "some model object",       tags: []    }; }]); 

i'm lost why doesn't work. according of isolate scope tutorials i've seen, should fine.

notes

passing controller parameter not option. third party library need interact this, , apparently can't twice on same html element.

your usage incorrect. work:

<body ng-app="app" ng-controller="homecontroller">    <div custom-directive="model"></div> </body>   app.directive('customdirective', [function() {    return {       restrict: "a",       scope: {          customdirective: "="       },       link: function(scope, element, attributes){           console.log(scope.customdirective); // $scope.model due 2-way binding       }    } }]) .controller('homecontroller', ['$scope', function($scope) {    $scope.model = {       id: "items/1",       name: "some model object",       tags: []    }; }]); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -

jquery - Keeping Kendo Datepicker in min/max range -