[英]unable to access $scope value in directive's controller
我有一個簡單的應用程序,但有些原因我無法訪問指令控制器中的$ scope值。
app.js
var myApp = angular.module('myApp',['ngAnimate']);
controller.js
myApp.controller('controller1',['$scope',function($scope) {
$scope.helloText = 'text';
}])
directive.js
myApp.directive('myPanel',function(){
return {
restrict : "E",
scope : {
someText : "="
},
templateUrl : 'someTemplate.html'
controller : function($scope) {
console.log($scope.someText);// this is undefined
}
};
});
someTemplate.html
<h1>This is the text {{someText}}</h1>
main.html中
<div ng-controller="controller1">
<my-panel someText="helloText"></my-Panel>
</div>
需要一些指示來了解我做錯了什么?
你的外殼已關閉。
<my-panel some-text="helloText"></my-Panel>
您可以閱讀指南中的規范化
直接來源
正常化
Angular規范化元素的標記和屬性名稱,以確定哪些元素與哪些指令匹配。 我們通常通過其區分大小寫的camelCase規范化名稱(例如ngModel)來引用指令。 但是,由於HTML不區分大小寫,我們通過小寫形式引用DOM中的指令,通常使用DOM元素上的划線分隔屬性(例如ng-model)。
規范化過程如下:
從元素/屬性的前面剝離x-和數據。 將:, - 或_分隔的名稱轉換為camelCase。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.