Alternative Solution:
After reviewing your updated question, it seems that achieving what you want is possible. The issue with your initial approach is that ng-required cannot execute a function, as it only reads a boolean value. However, we can create variables dynamically based on data from the server to automatically set fields as required:
Updated Plunker
<form>
Name: <input type="text" ng-model="user.test" ng-required="name" /><br/>
<input type="text" ng-model="user.name" ng-required="age" />
<br/>
<button type="submit">Submit</button>
</form>
I introduced a $scope property for each input in the ng-required attribute. By dynamically creating this $scope property and setting it to true according to our data, we can achieve the desired functionality:
$scope.isRequired = function(){
$scope.requiredFields = [];
$http.get('fields.json')
.success(function(data){
$scope.requiredFields = angular.fromJson(data);
console.log($scope.requiredFields.required)
for (i = 0; i < $scope.requiredFields.required.length; i++) {
$scope[$scope.requiredFields.required[i]] = true
}
console.log($scope[$scope.requiredFields.required[0]]);
})
//$scope.requiredFields = STUFF FROM SOME REST SERVICE
}
$scope.isRequired()
This script iterates over an array of required fields from the server, dynamically creating a $scope property for each required field and setting it to true. Any input with this $scope property in its ng-required will now be mandatory. Inputs without this dynamic property will not trigger the ng-required logic.
Original solution:
Plunker
As mentioned earlier, ng-required only accepts a Boolean value, but we can toggle this value using a function.
HTML
<form>
Name: <input type="text" ng-model="user.name" ng-required="isRequired" />
<br><button ng-click="toggle()">Required: {{isRequired}}</button>
<button type="submit">Submit</button>
</form>
JS code:
$scope.isRequired = true;
$scope.toggle = function() {
$scope.isRequired = !$scope.isRequired;
}