我在一个有角度的自举手风琴里面。
如下所示。
<accordion close-others="oneAtATime">
<accordion-group is-open="status.open">
<ng-form name="createAssetForm" onsubmit="" novalidate class="form-horizontal">
<fieldset>
<div class="form-group">
<label class="col-lg-2 control-label" for="AssetName">AssetName</label>
<div class="col-lg-10">
<div class="error error-msg" ng-show="(createAssetForm.AssetName.$dirty && createAssetForm.AssetName.$invalid && (!createAssetForm.AssetName.$focused))">
<small class="error"
ng-show="createAssetForm.AssetName.$error.minlength">
Project name is required to be at
least 3 characters
</small>
<small class="error" ng-show="createAssetForm.AssetName.$error.maxlength">
Project name cannot be longer than
250 characters
</small>
</div>
<input ng-focus ng-minlength="3" ng-maxlength="250" name="AssetName" class="form-control" type="text" placeholder="Asset Name" ng-model="NewAsset.AssetName" />
</div>
</div>
</fieldset>
</ng-form>
</accordion-group>
</accordion>
在我的控制器中,我无法访问
$scope.createAssetForm.$valid
此页面的路线是
.state('manageasset', {
url: '/userstories/projects/:projectid/asset',
templateUrl: '/app/userstories/assets/views/assetHome.html',
controller: 'US_assetController',
resolve: {
IsAuthenticated: ['AuthService', function (AuthService) {
return AuthService.isAuthendicatedPromised();
}]
},
data: {
isAuthenticated: true
}
})
请帮我找到问题!
答案 0 :(得分:0)
我不确定是不是更好的选择,但你可以使用$ watch访问它 请看例子:
var app = angular.module('app', []);
app.controller('firstCtrl', function($scope){
$scope.$watch('createAssetForm.$valid', function(value){
//value is your createAssetForm.$valid
$scope.isValid = value
});
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app">
<div ng-controller="firstCtrl">
Is form valid: {{isValid}}
<accordion close-others="oneAtATime">
<accordion-group is-open="status.open">
<ng-form name="createAssetForm" onsubmit="" novalidate class="form-horizontal" >
<fieldset>
<div class="form-group">
<label class="col-lg-2 control-label" for="AssetName">AssetName</label>
<div class="col-lg-10">
<div class="error error-msg" ng-show="(createAssetForm.AssetName.$dirty && createAssetForm.AssetName.$invalid && (!createAssetForm.AssetName.$focused))">
<small class="error"
ng-show="createAssetForm.AssetName.$error.minlength">
Project name is required to be at
least 3 characters
</small>
<small class="error" ng-show="createAssetForm.AssetName.$error.maxlength">
Project name cannot be longer than
250 characters
</small>
</div>
<input ng-focus ng-minlength="3" ng-maxlength="250" name="AssetName" class="form-control" type="text" placeholder="Asset Name" ng-model="NewAsset.AssetName" />
</div>
</div>
</fieldset>
</ng-form>
</accordion-group>
</accordion>
</div>
</div>