我应该为我的指令赋予什么范围,以便输入显示初始值 "Toto" ?我不想接受范围:true
HTML 代码:
<!doctype html>
<html ng-app="plunker" >
<head>
<meta charset="utf-8">
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.js"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<input customattr type = "text" ng-model="value.name" />
</body>
</html>
JS代码:
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.value = {"name":"Toto", "id":1};
});
app.directive('customattr', function () {
return {
restrict: 'A',
scope: {
},
link: function (scope, element, attrs) {
}
};
});
Plunker:http: //plnkr.co/edit/JxWElWhTeBbNpFHS0wYT