当我将 replace 属性设置为 true 时,浏览器崩溃了。这是 plunker 链接:http ://plnkr.co/edit/9pXdDGo4ccxljwIo3NN0 有什么问题?
索引.html
<!doctype html>
<html ng-app="cvApp" ng-cloak>
<head>
<meta charset="utf-8" />
<title>
Mixing Static And Dynamic Options In An AngularJS Select Menu
</title>
</head>
<body ng-controller="ctrl">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<div radios selected-option="selectedOption" option-list="optionList" name="ms">
</body>
</html>
radios.html
<label data-ng-repeat="opt in optionList" class="radio inline">
<input type="radio" name="{{name}}" ng-model="selectedOption" ng-value="opt" />
{{opt.name}}
</label>
脚本.js
var cvApp = angular.module('cvApp',[]);
cvApp.controller('ctrl', function ($scope) {
$scope.optionList=[{name:"evli",value:1},{name:"bekar",value:2}]
$scope.selectedOption=$scope.optionList[0];
});
cvApp.directive("radios", function() {
return {
restrict: "A",
//replace:true,
templateUrl: 'radios.html',
scope: {
selectedOption: "=",
optionList: "=",
name:"@"
}
};
});