我的Angular应用程序中有很多指令,所有这些指令似乎在95%的情况下按预期工作。最近我遇到了一个问题,有时我遇到一个或多个指令模板的$compile.tpload
错误。我没有运气调试这个问题。
这在本地和生产中都会发生,但只是偶尔发生(可能是5%的时间)。以下是我遇到此问题的一个指令的示例:
app.directive('client', ['$http', function($http) {
return {
replace: true,
templateUrl: '/assets/employers/client.html',
transclude: false,
scope: {
result: '=',
index: '=',
token: '@'
}, controller: ['$scope', '$http', function($scope, $http) {
// Omitted for brevity
}]
}
}]);
以下是我的client
指令的HTML:
<div class="clients row" ng-class="index % 2 === 0 ? 'even' : 'odd'">
<div class="col-lg-12">
<div class="results-label left" ng-if="result && result.name"><b>{{result.name}}</b></div>
<div ng-if="result && result.id" class="btn btn-default pull-right" ng-click="edit()">Edit</div>
<form ng-show="showEditor" accept-charset="UTF-8" name="companyForm" ng-submit="submit(company);" novalidate>
<input name="utf8" type="hidden" value="✓">
<input name="authenticity_token" type="hidden" ng-model="company.token">
<div class="form-group">
<label>Company Name</label>
<input type="text" class="form-control" name="name" ng-model="company.name" required>
</div>
<div class="form-group">
<label>Authorized Users</label>
<div ng-repeat="i in company.employers_attributes">
<div ng-hide="i._destroy" class="row form-group">
<div class="col-lg-2">
<a ng-click="removeUser($index)" class="btn btn-xs btn-danger">X</a>
</div>
<div class="col-lg-10">
<label>First Name</label>
<input class="form-control" ng-model="company.employers_attributes[$index].first_name" />
<label>Last Name</label>
<input class="form-control" ng-model="company.employers_attributes[$index].last_name" />
<label>Email</label>
<input class="form-control" ng-model="company.employers_attributes[$index].email" />
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="btn btn-default" ng-click="addUser()">
<i class="fa fa-plus"></i>
Add User
</div>
<input class="btn btn-primary" style="float:right;" name="commit" type="submit" value="Save" ng-disabled="companyForm.$invalid">
</div>
</form>
</div>
</div>