limitless.directive('multiRadio', ['config', function (config) { return { restrict: 'E', replace: true, templateUrl: config.baseUrl + 'app/shared/multiradioDirectiveView.html', scope: { source: '=', model: '=', name: '=' }, controller: function ($scope) { $scope.$watch('source', function (newv, oldv) { if (newv !== oldv) { $scope.model = null; } for (var i = 0; i < $scope.source.length; i++) $scope.source[i].$description = $scope.source[i][$scope.descriptionSelector]; }); $scope.onChange = function (item) { if (item.$state) $scope.model = item; }; $scope.isChecked = function (item) { if ($scope.model == null) return false; return item[$scope.comparatorSelector] == $scope.model[$scope.comparatorSelector]; }; }, link: function ($scope, el, attrs) { $scope.comparatorSelector = attrs.selector; $scope.descriptionSelector = attrs.description; $scope.groupName = attrs.name; } } }]);