这是我的简单控制器和指令:
var myApp = angular.module('myApp',[]);
function MyCtrl($scope, $q) {
var myObject = {
name: "Dingus",
favoriteFood: "Chicken",
};
var itemDeferred = $q.defer();
$scope.item = itemDeferred.promise;
var resolveIt = function() {
itemDeferred.resolve(myObject);
};
resolveIt();
}
myApp.directive('promised', function() {
return {
restrict: 'E',
scope: { boundModel: '=' },
template: '<input type="text" ng-model="boundModel">',
};
});
范围项是从一个承诺中解决的。当我ng-model
在 HTML 中使用时,为什么输入不更新项目,为什么指令甚至不让我输入?
请参阅此小提琴以获取工作示例:http: //jsfiddle.net/winduptoy/XmBxK/