AngularJS - ngClick 不适用于动态添加的 html [英] AngularJS - ngClick not working on dynamically added html
本文介绍了AngularJS - ngClick 不适用于动态添加的 html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的应用程序,其中有一个带有 mylist
模型的输入元素.如果 mylist=1
ng-include first.html,如果 mylist=2
ng-include second.html.到现在为止还挺好.
我的问题是,在每个 html 模板中,我都有一个按钮,单击该按钮时我想更改 mylist
的值,以便我可以导航到另一个模板,为了实现这一点,我这样做:
<button ng-click="mylist=x" >切换到 x</button>
但 ng-click 不起作用.为什么?
这是我的代码:
scripts.js
var myApp = angular.module('myApp', []);myApp.controller('MainController', function ($scope) {$scope.mylist = 1;});
index.html
<html ng-app="myApp"><头><script src="https://code.angularjs.org/1.2.16/angular.js"></script><script src="script.js"></script>头部><body ng-controller="MainController"><input type="number" ng-model="mylist"/>{{mylist}}<br/><div ng-switch on="mylist"><div ng-switch-when=1><ng-include src="'first.html'"></ng-include>
<div ng-switch-when=2><ng-include src="'second.html'"></ng-include>