为什么我的范围对象中的嵌套对象中不能这样绑定:
app.directive('myDirective', function() {
return {
scope: {
dropdown: {
option: '=selectedOption' //not working
}
}
}
})
我收到一个错误:
a.match不是函数
这是一个正在工作的家伙。
“为什么”的答案是“因为那不是它的工作方式”。
解析指令范围的AngularJS源代码在这里:https : //github.com/angular/angular.js/blob/master/src/ng/compile.js#L829
function parseIsolateBindings(scope, directiveName, isController) {
var LOCAL_REGEXP = /^\s*([@&]|=(\*?))(\??)\s*(\w*)\s*$/;
var bindings = {};
forEach(scope, function(definition, scopeName) {
var match = definition.match(LOCAL_REGEXP);
if (!match) {
throw $compileMinErr('iscp',
"Invalid {3} for directive '{0}'." +
" Definition: {... {1}: '{2}' ...}",
directiveName, scopeName, definition,
(isController ? "controller bindings definition" :
"isolate scope definition"));
}
bindings[scopeName] = {
mode: match[1][0],
collection: match[2] === '*',
optional: match[3] === '?',
attrName: match[4] || scopeName
};
});
return bindings;
}
如您所见,它只遍历scope
对象属性,而不会递归地降入对象属性。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句