详细谈谈AngularJS的子级作用域问题(2)

<!DOCTYPE html> <html lang="en" ng-app="childScope"> <head> <meta charset="UTF-8"> <title></title> <script src="https://www.jb51.net/lib/angular.min.js" type="text/javascript"></script> <style> .inputOne{ width: 100px; height: 50px; background: skyblue; } .inner{ border: 1px solid skyblue; width: 200px; height: 150px; } .outer{ border: 1px solid salmon; width: 200px; height: 150px; } .sco{ background: skyblue; } </style> </head> <body ng-controller="childCon"> <div> <h3>父级作用域</h3> <span>{{private1}}</span> <span>{{private2}}</span> </div> <div> <h3>自己作用域</h3> <div ng-include src="'https://www.jb51.net/one.html'"></div> <div ng-include src="'https://www.jb51.net/two.html'"></div> </div> </body> <script> var app=angular.module("childScope",['template']) .controller("childCon",["$scope", function ($scope) { $scope.private1=12; $scope.private2=22; $scope.test=123; }]); var template=angular.module("template",[]) .run(["$templateCache", function ($templateCache) { $templateCache.put("https://www.jb51.net/one.html","" + "<div><input type='text' ng-model='$parent.private1'/></div>") }]) .run(["$templateCache", function ($templateCache) { $templateCache.put("https://www.jb51.net/two.html","" + "<div><input type='text' ng-model='$parent.private2'/>" + "<div><span>原始类型</span>{{test}}</div>" + "</div>") }]) </script> </html>

总结

以上就是AngularJS子级作用域问题的全部内容,希望对大家学习和工作能有所帮助。大家如果有什么疑问,欢迎提出来。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzfwgp.html