2

私はjs/html/cssなどに不慣れで、Angularを教えようとしていますが、単純に見えるものにこだわっています。

以下に説明するページをロードすると、タイトルと、Angular で置き換えたいテキストを含む 1 つの項目リストが取得されます。「{{e.someKey}}」。私が探しているのは、someValue1 と someValue2 の 2 つの箇条書きです。

index.html で:

<!doctype html>
<html lang="en" ng-app="myfirstapp">
<head>
  <meta charset="utf-8">
  <title>my first app</title>
  <link rel="stylesheet" href="css/app.css">
  <link rel="stylesheet" href="css/bootstrap.css">
  <script src="lib/angular/angular.js"></script>
  <script src="js/app.js"></script>
  <script src="js/controllers.js"></script>
</head>
<body>
  <h1>My First App</h1>
  <div ng-controller="MyFirstAppController">
    <ul>
      <li ng-repeat="e in elementArray">
        <p>{{e.someKey}}</p>
      </li>
    </ul>
  </div>
</body>
</html>

コントローラーは次のようになります。

function MyFirstAppController($scope) {
    $scope.elementArray = [
        { someKey : 'someValue1', someOtherKey : 'someOtherValue1' },
        { someKey : 'someValue2', someOtherKey : 'someOtherValue2' }
    ];
}

これに対して多くの構文調整を試みましたが、もっと基本的なものが欠けているに違いありません。どんなアイデアでも大歓迎です!

4

1 に答える 1

1

単純に次のように変更します。

<html lang="en" ng-app>

JSFiddle の動作バージョンは次のとおりです: http://jsfiddle.net/EgPYA/

于 2012-11-29T02:43:11.747 に答える