我想模仿 kendo-grid 中自定义编辑器的行为,但我遇到了访问传递的对象的问题 data-bind =" value:currentObjInGrid&#34
我有这个示例html
<div ng-app="TestApp">
<div ng-controller="TestCtrl">
<div custom-input="MyInput" data-bind="value:Hey"></div>
</div>
</div>
和javascript
var app = angular.module('TestApp', []);
app.controller('TestCtrl', ['$scope', function($scope){
$scope.Hey = {
A: 'Jude',
B: 'John'
};
}]);
app.directive("customInput", function ($timeout, $compile) {
return {
restrict: "EA",
scope: {
customInput: '@',
bind: '='
},
transclude: true,
template: '<button>Hi</button>',
controller: function($scope){
// i want to access the content of 'Hey' here
// as 2 way binding or pass by reference
// but i can't access it
console.log($scope);
}
}
});
这是从数据绑定访问对象的正确方法吗?
任何帮助都将不胜感激。
这里是fiddle
答案 0 :(得分:0)
你不应该使用data-bind =“value:嘿”因为这是Kendo UI MVVM的一部分。它不适用于AngularJS。如果要获取bind属性的值,可以这样做:
<div custom-input="MyInput" data-bind="Hey"></div>
然后使用$ scope的Hey属性:
controller: function($scope){
// i want to access the content of 'Hey' here
// as 2 way binding or pass by reference
// but i can't access it
console.log($scope.bind);
}