0

Hi I'm creating an Angular bootstrap popover, and the popover contains a directive. The user story is that when the user clicks on a row inside an ui-grid table, the popover will show. But it seems that in HTML code the data is not actually passed into the directive. Related code is here:

search.tpl.html:

<div class="gridStyle" ui-grid="vm.selectedTypes" ui-grid-resize-columns ui-grid-selection style="margin-top: 0px; z-index: 4; position: relative">
</div>

<script type="text/ng-templae" id="popover.html">
    <div style="z-index:10; position: relative">
        <type-view type="vm.type" domain="vm.domain" pos="{top: 0, left: 0}">
        </type-view>
    </div>
</script>

search.js:

//In configure
controllerAs: "vm",
...
//In controller
var vm=this;

vm.type=[...];
vm.domain=[...]; //both var get values inside

Now the popover is shown, and the directive is inside, but the values (vm.type and vm.domain) are not injected into the directive; I checked the console, and in the directive 'pos' is injected, so I suppose maybe it's because the scope is different inside a popover and directly using vm.sth will not work. How can I resolve this? Thanks!

richards
  • 517
  • 9
  • 27
  • Is vm a member of the scope, or are you using controllerAs? Need a bit more information. – GBa Jun 09 '16 at 01:38
  • Sorry didn't clarify; controllerAs: "vm" – richards Jun 09 '16 at 01:41
  • Try putting {{vm.type}} in your template somewhere to see if the proper value is set. If it is set, and the binding is of type @, one guess is you might need to pass in type="{{vm.type}}" – GBa Jun 09 '16 at 01:44
  • Hmm I think for directives no need to include {{}} for params passed in; just using "vm.sth" should be the correct way. – richards Jun 09 '16 at 01:56
  • It depends, an @ binding requires a literal value, so you need the @. If the binding is '=', '<' or &, then you wouldn't use the {{}}. – GBa Jun 09 '16 at 01:59
  • I see. But for this case if I include {{}} then things will go wrong: other attributes will not be recognized by the directive either. – richards Jun 09 '16 at 02:05

0 Answers0