Mr_*_*een 1 html javascript templates angularjs
我是angularjs的新手.我有一个要求,我在每个部分HTML中一次又一次地使用相同的单选按钮.所以,我想把它作为一个通用模板,并在其他部分模板中使用它.
<ng-include src="'partial-htmls/toolbox/radio-button.html'"></ng-include>
Run Code Online (Sandbox Code Playgroud)
其中显示单选按钮如下:
Sex : O Male
O Female
Run Code Online (Sandbox Code Playgroud)
这很好但我需要以某种方式改变标签,文本和单选按钮的数量ng-include.(我想通过以某种方式传递params来做)
I am from background of lodash, where it can be easily handled. I thought there might be a way in angular too.
Please help.
没有办法将参数传递给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
}]
};
}]);
Run Code Online (Sandbox Code Playgroud)
<radio-button pass="parentScopeObject" some="Literal string" properties="parentScopeSomething"></radio-button>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3469 次 |
| 最近记录: |