2015-06-04 49 views
0

我有一个指令,如下所示的自定义指令,我希望能够通过templateUrl在自定义指令angularjs传递字符串属性为templateUrl

<div ng-if="box.key === 'experiences'" 
    experiences-form 
    template-url="'experiences.php'" // template url I am trying to pass 
    item="item" 
    forms="forms" 
    form-name="{{box.key}}{{item._id}}" 
    onsave="updateMultipleUser(box.key, item._id, $data)" 
    cancel="formAction($formName, 'cancel')" 
    > 
</div> 

DDO的指令

{ 
    restrict: 'A', 
    replace: true, 
    scope: { 
     onsave: '&', 
     cancel: '&', 
     formName: '@', 
     forms: '=', 
     item: '=' 
    }, 
    controller: controller, 
    templateUrl: function (tElement, tAttrs) { 
     return tAttrs.templateUrl; // returns 'experiences.php' how to get rid of the single quotes? 
    } 
}; 
+1

只需删除它们。 – zeroflagL

+0

好吧,我得到了他们删除他们来说,这是行不通的,我第一次尝试,由于某种原因,我想如果没有把单引号,它会尝试和寻找一个$ scope.experiences.php工作 – ericsicons

回答

0

你为什么把引号中templateUrl属性? 它应该只是这样的:

<div ng-if="box.key === 'experiences'" 
    experiences-form 
    template-url="experiences.php" // template url I am trying to pass 
    item="item" 
    forms="forms" 
    form-name="{{box.key}}{{item._id}}" 
    onsave="updateMultipleUser(box.key, item._id, $data)" 
    cancel="formAction($formName, 'cancel')" 
    > 
</div> 

如果它不工作,你可以复制并粘贴错误消息,或者你得到的结果呢?

0

尝试

return tAttrs.templateUrl.replace(/^'|'$/g,"") 

虽然建议将remov Ë这些单引号template-url="'experiences.php'"或在其中创建