zoukankan      html  css  js  c++  java
  • 学习angularjs时遇到 XX is not a function

    出现这个问题是因为在 angularJs 1.3 中 为了让 根节点上(rootScope)不再被挂上许多冗余的内容,所以禁止了直接在根上注册controller。

    第一:以后不能直接以  function XXXcontroller (){ code......}这样的方式直接注册监听器了。以后必须

    angular.module('phonecatApp', []).controller('PhoneListCtrl',function($scope) {}这样来将controller注册到对应的模型上。

    第二:  在 ng-aap 中指定相对应的模型。

    如 之前:

    <html ng-app>(不指定则为根元素)

    现在:

    <html ng-app="phonecatApp">

    <DOCTYPE html>
    <html ng-app="HelloApp">
    <head>
    <title>test</title>
    <script src="../../angular.js"></script>
    </head>
    <body ng-controller="CartController">
    <h1>your Order</h1>
    <div ng-repeat='item in items'>
    <span>{{item.title}}</span>
    <input ng-model='item.quantity' >
    <span> {{item.price}} </span>
    <span>{{item.price*item.quantity}}</span>
    <button ng-click="remove($index)">Remove</button>
    </div>

    <script type="text/javascript">
    angular.module("HelloApp", []).controller("CartController", function($scope){
    $scope.items=[
    { title: 'paint pots', quantity: 8, price:3.95 },
    { title: 'polka dots', quantity: 17, price: 12.95},
    { title: 'Pebbles', quantity: 5, price: 6.95}
    ];

    $scope.remove = function(index){
    $scope.items.splice(index,1);
    }

    });




    </script>
    </body>
    </html>

  • 相关阅读:
    定时器工厂
    无聊js画了个菱形
    盒模型之滚动条
    无聊,纯css写了个评分鼠标移入的效果
    json属性名为什么要双引号?
    原生js写的一个简单slider
    D2 前端技术论坛总结(上)
    第一天,入坑 —— 2014.10.24
    获取div相对文档的位置
    我们平时是怎么写html和css的?
  • 原文地址:https://www.cnblogs.com/facial/p/4524847.html
Copyright © 2011-2022 走看看