我想直接从属性指令中获取一个值:
<form cronos-dataset="People as p">
Form Content
</form>
在我的 JS 中我试过:
app.directive('cronosDataset',[function() {
return {
restrict: 'A',
controller: 'CronosGenericDatasetController',
scope: {
"cronos-dataset" : '@'
}
};
}])
.controller("CronosGenericDatasetController",['$scope', function($scope) {
alert($scope["cronos-dataset"]);
}]);
我想提醒 "People as p"
字符串,但我得到 undefined
。这是正确的道路还是我应该彻底采用不同的方法?
最佳答案
你应该在范围声明中使用驼峰式命名
app.directive('cronosDataset',[function() {
return {
restrict: 'A',
controller: 'CronosGenericDatasetController',
scope: {
cronosDataset : '@'
}
};
}])
这是一个演示,可以看到不同的变化 http://plnkr.co/edit/G6BiGgs4pzNqLW2sSMt7?p=preview
关于javascript - Angular 属性指令值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28856788/