我需要从选择中调用AngularJS函数:
<select ng-model="selection" >
<option onselect="angular.element(this).scope().functionCall('one')">one</option>
<option onselect="angular.element(this).scope().functionCall('two')">two</option>
<option onselect="angular.element(this).scope().functionCall('three')">three</option>
<option onselect="angular.element(this).scope().functionCall('four')">four</option>
</select>
Run Code Online (Sandbox Code Playgroud)
但是,函数永远不会被调用.
在控制器中,
$scope.functionCall = function(value){
// do stuff with value
}
Run Code Online (Sandbox Code Playgroud)
我该如何调用该功能.
我有一个div实例化ace编辑器对象.
我试图drag and drop从一个文本到它HTML draggable.
我已经制作了ui-ace div droppable并希望从drop的事件目标中获取编辑器的当前实例.
我该怎么做到这个???
HTML
<div id="id1" ui-ace droppable=true ondrop="handleDrop(event,this)"></div>
Run Code Online (Sandbox Code Playgroud)
JS功能
function handleDrop(e,obj){
// need code to get current editor instance from obj without using ace.edit(obj.id)
// because ace.edit(obj.id) will reset the content I believe. Please correct me if I am
//wrong. Ace api says it will insert editor in the DOM. http://ace.c9.io/#nav=api&api=ace
}
Run Code Online (Sandbox Code Playgroud)
请帮忙.
我一定很遗憾.我得到错误$ scope未在plunker中定义.错误在哪里?我已经声明了模块,控制器和依赖项,我无法看到错误的位置.
var phonecatApp = angular.module('phonecatApp', [$scope]);
phonecatApp.controller('PhoneListCtrl', function () {
$scope.phones = [
{'name': 'Nexus S',
'snippet': 'Fast just got faster with Nexus S.',
'age': 1},
{'name': 'Motorola XOOM™ with Wi-Fi',
'snippet': 'The Next, Next Generation tablet.',
'age': 2},
{'name': 'MOTOROLA XOOM™',
'snippet': 'The Next, Next Generation tablet.',
'age': 3}
];
$scope.orderProp = 'age';
});
<html ng-app='phonecatApp'>
<head>
<title>My Angular App</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<div ng-controller="PhoneListCtrl">Search: <input ng-model="query">
Sort by:
<select ng-model="orderProp">
<option value="name">Alphabetical</option>
<option value="age">Newest</option> …Run Code Online (Sandbox Code Playgroud)