के साथ निर्देश और नियंत्रक के बीच दायरे को सही ढंग से बाध्य करने के लिए कैसे मैं anugularJS के साथ एक एन-स्तरीय पदानुक्रमित अनॉर्डर्ड सूची उत्पन्न करने की कोशिश कर रहा हूं, और सफलतापूर्वक ऐसा करने में सक्षम हूं। लेकिन अब, मुझे निर्देश और नियंत्रक के बीच दायरे के मुद्दे हैं। मुझे निर्देश टेम्पलेट में एनजी-क्लिक के माध्यम से बुलाए गए फ़ंक्शन के भीतर माता-पिता की एक स्कोप प्रॉपर्टी बदलने की आवश्यकता है।कोणीय जेएस
http://jsfiddle.net/ahonaker/ADukg/2046/ देखें - यहाँ जे एस
var app = angular.module('myApp', []);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
function MyCtrl($scope) {
$scope.itemselected = "None";
$scope.organizations = {
"_id": "SEC Power Generation",
"Entity": "OPUNITS",
"EntityIDAttribute": "OPUNIT_SEQ_ID",
"EntityID": 2,
"descendants": ["Eastern Conf Business Unit", "Western Conf Business Unit", "Atlanta", "Sewanee"],
children: [{
"_id": "Eastern Conf Business Unit",
"Entity": "",
"EntityIDAttribute": "",
"EntityID": null,
"parent": "SEC Power Generation",
"descendants": ["Lexington", "Columbia", "Knoxville", "Nashville"],
children: [{
"_id": "Lexington",
"Entity": "OPUNITS",
"EntityIDAttribute": "OPUNIT_SEQ_ID",
"EntityID": 10,
"parent": "Eastern Conf Business Unit"
}, {
"_id": "Columbia",
"Entity": "OPUNITS",
"EntityIDAttribute": "OPUNIT_SEQ_ID",
"EntityID": 12,
"parent": "Eastern Conf Business Unit"
}, {
"_id": "Knoxville",
"Entity": "OPUNITS",
"EntityIDAttribute": "OPUNIT_SEQ_ID",
"EntityID": 14,
"parent": "Eastern Conf Business Unit"
}, {
"_id": "Nashville",
"Entity": "OPUNITS",
"EntityIDAttribute": "OPUNIT_SEQ_ID",
"EntityID": 4,
"parent": "Eastern Conf Business Unit"
}]
}]
};
$scope.itemSelect = function (ID) {
$scope.itemselected = ID;
}
}
app.directive('navtree', function() {
return {
template: '<ul><navtree-node ng-repeat="item in items" item="item" itemselected="itemselected"></navtree-node></ul>',
restrict: 'E',
replace: true,
scope: {
items: '='
}
};
});
app.directive('navtreeNode', function ($compile) {
return {
restrict: 'E',
template: '<li><a ng-click="itemSelect(item._id)">{{item._id}} - {{itemselected}}</a></li>',
scope: {
item: "=",
itemselected: '='
},
controller: 'MyCtrl',
link: function (scope, elm, attrs) {
if ((angular.isDefined(scope.item.children)) && (scope.item.children.length > 0)) {
var children = $compile('<navtree items="item.children"></navtree>')(scope);
elm.append(children);
}
}
};
});
है और यहाँ एचटीएमएल
<div ng-controller="MyCtrl">
Selected: {{itemselected}}
<navtree items="organizations.children"></navtree>
</div>
नोट सूची मॉडल से उत्पन्न होता है है। और ng-click पैरेंट स्कोप प्रॉपर्टी (आइटम चयन) सेट करने के लिए फ़ंक्शन को कॉल करता है, लेकिन परिवर्तन केवल स्थानीय रूप से होता है। अपेक्षित व्यवहार, जब मैं किसी आइटम पर क्लिक करता हूं, तो यह है कि "चयनित: कोई नहीं" को "चयनित: xxx" में बदलना चाहिए जहां xxx वह आइटम है जिसे क्लिक किया गया था।
क्या मैं मूल दायरे और निर्देश के बीच संपत्ति को बाध्य नहीं कर रहा हूं? मैं संपत्ति के दायरे में संपत्ति परिवर्तन कैसे पास करूं?
आशा है कि यह स्पष्ट है।
किसी भी मदद के लिए अग्रिम धन्यवाद।
स्टैक ओवरव्लो में आपका स्वागत है! यदि आप अंत के पास एक वास्तविक प्रश्न के रूप में इसे दोहराते हैं तो यह आपकी पोस्ट को बेहतर बना सकता है। –