我創建了一個指令,允許我重現一些包含輸入字段的HTML。問題在於輸入呈現時,值域填充了範圍內的值,但由於某種原因未顯示。角度指令生成的輸入元素不顯示值
不適用於Chrome,Firefox或MS Edge。你可以看看這個Plunkr
HTML:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-directive-simple-production</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="docsSimpleDirective">
<div ng-controller="Controller">
<form-input i-scope="customer" e-scope="errors" model="customer.name" name="name"></form-input>
</div>
</body>
</html>
JS
(function(angular) {
'use strict';
angular.module('docsSimpleDirective', [])
.controller('Controller', ['$scope', function($scope) {
$scope.customer = {
name: 'Naomi',
address: '1600 Amphitheatre'
};
$scope.errors = {name:"name is required"};
}])
.directive('formInput', function() {
return {
restrict: "E",
scope: {
formInfo:'=iScope',
errors:'=eScope'
},
replace:true,
template: function(elem,attr){
return '<div><input type="text" name="' + attr.name + '" id="' + attr.name + '" ng-model="' + attr.model + '" value="{{ formInfo.' + attr.name + '}}" /><span ng-cloak ng-show="errors.' + attr.name + '">{{ errors.' + attr.name + ' }}</span></div>';
}
};
});
})(window.angular);
UPDATE 請看看在Plunkr作爲代碼現已更新爲了展示真實的問題,使用如上所述的ng值解決了基本示例通過@ Stefan.B,但並沒有解決原來的問題
將這一對plunker使得它的工作,但它應用到項目不因某種原因。該值將返回到值字段中,但不會顯示在用戶的瀏覽器輸入字段中。任何其他想法?我會更新重擊器以嘗試完全複製這個 –
請查看更新的Plunkr –