我有一个被整个应用程序使用的全局搜索变量
newspaper.controller("MainController", function($scope) {
$scope.search = {query:''};
});
然后我有一个我想绑定到 $scope.search 的 contenteditable div
app.directive('search', function() {
return {
restrict: 'AE',
replace: true,
template: '<div ng-model="query" id="search"></div>',
scope: {
query: '='
},
controller: function($scope) {
// I want to watch the value of the element
$scope.$watch('query', function(newValue, oldValue){
console.log(newValue);
},true);
},
link: function(scope, element, attrs) {
// Medium JS content editable framework
new Medium({
element: element[0],
mode: Medium.inlineMode
});
}
}
});
当我在 div 中输入新值时手表没有触发,我想我仍然对如何将指令与模型链接感到困惑。这是HTML
<nav ng-controller="MainControllerr">
<search context="search.query"></np-search>
</nav>