簡體   English   中英

在ng-include中傳遞參數

[英]Pass params in ng-include

我是angularjs的新手。 我有一個要求,我在每個部分html中一次又一次地使用相同的單選按鈕。 因此,我想將其作為通用模板並在其他部分模板中使用。

<ng-include src="'partial-htmls/toolbox/radio-button.html'"></ng-include>

顯示單選按鈕如下:

Sex :    O Male
         O Female

很好,但是我需要在ng-include以某種方式更改標簽,文本和單選按鈕的數量。 我想通過傳遞參數來實現

我來自lodash的背景,可以輕松處理它。 我認為也許也可以采用角度方式。

請幫忙。

無法將參數傳遞給ng-include
但是,它確實可以訪問與其所在HTML相同的作用域。

如果需要能夠傳遞不同的參數,則必須使用指令:

angular.module("myModule")
.directive('radioButton', [function () {
    return {
        restrict: 'E',
        scope: {
            pass: "=",
            some: "@",
            properties: "="
        },
        templateUrl: 'app/directives/views/radio-row.html',
        controller: ["$scope", function ($scope) {
            // Isolated $scope here
        }]
    };
}]);
<radio-button pass="parentScopeObject" some="Literal string" properties="parentScopeSomething"></radio-button>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM